List Directory
curl --request GET \
--url https://api.declaw.ai/sandboxes/{sandbox_id}/files/list \
--header 'X-API-Key: <api-key>'import requests
url = "https://api.declaw.ai/sandboxes/{sandbox_id}/files/list"
headers = {"X-API-Key": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'X-API-Key': '<api-key>'}};
fetch('https://api.declaw.ai/sandboxes/{sandbox_id}/files/list', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.declaw.ai/sandboxes/{sandbox_id}/files/list",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.declaw.ai/sandboxes/{sandbox_id}/files/list"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-API-Key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.declaw.ai/sandboxes/{sandbox_id}/files/list")
.header("X-API-Key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.declaw.ai/sandboxes/{sandbox_id}/files/list")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-API-Key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"[].name": "<string>",
"[].path": "<string>",
"[].type": "<string>",
"[].size": 123
}Filesystem API
List Directory
List the entries of a directory inside a sandbox.
GET
/
sandboxes
/
{sandbox_id}
/
files
/
list
List Directory
curl --request GET \
--url https://api.declaw.ai/sandboxes/{sandbox_id}/files/list \
--header 'X-API-Key: <api-key>'import requests
url = "https://api.declaw.ai/sandboxes/{sandbox_id}/files/list"
headers = {"X-API-Key": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'X-API-Key': '<api-key>'}};
fetch('https://api.declaw.ai/sandboxes/{sandbox_id}/files/list', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.declaw.ai/sandboxes/{sandbox_id}/files/list",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.declaw.ai/sandboxes/{sandbox_id}/files/list"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-API-Key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.declaw.ai/sandboxes/{sandbox_id}/files/list")
.header("X-API-Key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.declaw.ai/sandboxes/{sandbox_id}/files/list")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-API-Key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"[].name": "<string>",
"[].path": "<string>",
"[].type": "<string>",
"[].size": 123
}Returns the immediate children (files and subdirectories) of the specified
directory path. Does not recurse into subdirectories.
Path Parameters
string
required
The sandbox identifier. Format:
sbx-<8 chars>.Query Parameters
string
required
Absolute path of the directory to list inside the sandbox.Example:
/home/userResponse
Returns an array ofEntryInfo objects, one per directory entry.
string
Entry filename or directory name (not the full path).
string
Full absolute path inside the sandbox.
string
Entry type:
"file", "dir", or "symlink".integer
Size in bytes.
0 for directories.Example
curl "https://api.declaw.ai/sandboxes/sbx-a1b2c3d4/files/list?path=/home/user" \
-H "X-API-Key: YOUR_API_KEY"
from declaw import Sandbox
sbx = Sandbox.connect("sbx-a1b2c3d4", api_key="YOUR_API_KEY", domain="api.declaw.ai")
entries = sbx.files.list("/home/user")
for entry in entries:
print(entry.name, entry.type, entry.size)
import { Sandbox } from "@declaw/sdk";
const sbx = await Sandbox.connect("sbx-a1b2c3d4", {
apiKey: "YOUR_API_KEY",
domain: "api.declaw.ai",
});
const entries = await sbx.files.list("/home/user");
for (const entry of entries) {
console.log(entry.name, entry.type, entry.size);
}
Response
[
{
"name": "script.py",
"path": "/home/user/script.py",
"type": "file",
"size": 1024
},
{
"name": "data",
"path": "/home/user/data",
"type": "dir",
"size": 0
}
]
Error Responses
| Status | Cause |
|---|---|
401 | Missing or invalid API key |
404 | Sandbox not found |
502 | envd daemon unreachable |
503 | Sandbox has no VM |
⌘I