Skip to main content
POST
/
sandboxes
/
{sandbox_id}
/
files
Write File
curl --request POST \
  --url https://api.declaw.ai/sandboxes/{sandbox_id}/files \
  --header 'Content-Type: application/json' \
  --header 'X-API-Key: <api-key>' \
  --data '
{
  "path": "<string>",
  "data": "<string>",
  "username": "<string>"
}
'
Writes a file to the specified path inside the sandbox. If the file already exists it is overwritten. Parent directories are created automatically if they do not exist. Returns the envd write response.

Path Parameters

sandbox_id
string
required
The sandbox identifier. Format: sbx-<8 chars>.

Request Body

path
string
required
Absolute path to write inside the sandbox. Parent directories are created automatically.Example: "/home/user/script.py"
data
string
required
File content as a UTF-8 string. This endpoint is text-only — it cannot carry arbitrary bytes. For binary payloads (images, compiled artifacts, base64-decoded blobs) use the streaming PUT /files/raw endpoint with Content-Type: application/octet-stream (500 MiB cap). The Python and TypeScript SDKs dispatch automatically based on payload type — pass bytes / Uint8Array to files.write() and the SDK routes to /files/raw for you.Example: "print('hello')\n"
username
string
Unix user to own the written file. Defaults to the envd default user.Example: "user"

Response

Returns the envd write confirmation as a JSON object.

Example

curl -X POST https://api.declaw.ai/sandboxes/sbx-a1b2c3d4/files \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "path": "/home/user/script.py",
    "data": "print(\"hello\")\n"
  }'

Error Responses

StatusCause
400Invalid request body
401Missing or invalid API key
404Sandbox not found
409Sandbox is paused — resume it before accessing files
410Sandbox has been killed
502envd daemon unreachable
503Sandbox has no VM