Write File (Raw / Binary)
curl --request PUT \
--url https://api.declaw.ai/sandboxes/{sandbox_id}/files/raw \
--header 'Content-Type: <content-type>' \
--header 'X-API-Key: <api-key>'import requests
url = "https://api.declaw.ai/sandboxes/{sandbox_id}/files/raw"
headers = {
"Content-Type": "<content-type>",
"X-API-Key": "<api-key>"
}
response = requests.put(url, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'Content-Type': '<content-type>', 'X-API-Key': '<api-key>'}
};
fetch('https://api.declaw.ai/sandboxes/{sandbox_id}/files/raw', 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/raw",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_HTTPHEADER => [
"Content-Type: <content-type>",
"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/raw"
req, _ := http.NewRequest("PUT", url, nil)
req.Header.Add("Content-Type", "<content-type>")
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.put("https://api.declaw.ai/sandboxes/{sandbox_id}/files/raw")
.header("Content-Type", "<content-type>")
.header("X-API-Key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.declaw.ai/sandboxes/{sandbox_id}/files/raw")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Content-Type"] = '<content-type>'
request["X-API-Key"] = '<api-key>'
response = http.request(request)
puts response.read_bodyFilesystem API
Write File (Raw / Binary)
Stream raw bytes into a sandbox file. Binary-safe, up to 500 MiB per request.
PUT
/
sandboxes
/
{sandbox_id}
/
files
/
raw
Write File (Raw / Binary)
curl --request PUT \
--url https://api.declaw.ai/sandboxes/{sandbox_id}/files/raw \
--header 'Content-Type: <content-type>' \
--header 'X-API-Key: <api-key>'import requests
url = "https://api.declaw.ai/sandboxes/{sandbox_id}/files/raw"
headers = {
"Content-Type": "<content-type>",
"X-API-Key": "<api-key>"
}
response = requests.put(url, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'Content-Type': '<content-type>', 'X-API-Key': '<api-key>'}
};
fetch('https://api.declaw.ai/sandboxes/{sandbox_id}/files/raw', 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/raw",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_HTTPHEADER => [
"Content-Type: <content-type>",
"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/raw"
req, _ := http.NewRequest("PUT", url, nil)
req.Header.Add("Content-Type", "<content-type>")
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.put("https://api.declaw.ai/sandboxes/{sandbox_id}/files/raw")
.header("Content-Type", "<content-type>")
.header("X-API-Key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.declaw.ai/sandboxes/{sandbox_id}/files/raw")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Content-Type"] = '<content-type>'
request["X-API-Key"] = '<api-key>'
response = http.request(request)
puts response.read_bodyStreams the request body directly into a file on the sandbox disk without
buffering in memory. Use this endpoint for any binary payload — images,
archives, compiled artifacts, base64-decoded blobs — or for uploads larger
than the 10 MiB JSON gateway cap.
For UTF-8 text, the JSON
POST /files
endpoint is usually the simpler choice.
Path Parameters
string
required
The sandbox identifier. Format:
sbx-<8 chars>.Query Parameters
string
required
Absolute path to write inside the sandbox. Parent directories are created
automatically.Example:
/home/user/image.pngstring
Unix user to own the written file. Defaults to the envd default user.
Request Headers
string
required
Must be
application/octet-stream.Request Body
Raw bytes. Up to 500 MiB per request. The body is streamed to disk with a flat memory footprint on the orchestrator.Response
{
"path": "/home/user/image.png",
"size": 4096
}
Example
curl -X PUT "https://api.declaw.ai/sandboxes/sbx-a1b2c3d4/files/raw?path=/home/user/image.png" \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/octet-stream" \
--data-binary @image.png
from declaw import Sandbox
sbx = Sandbox.connect("sbx-a1b2c3d4", api_key="YOUR_API_KEY", domain="api.declaw.ai")
# The SDK automatically routes bytes payloads to /files/raw.
with open("image.png", "rb") as f:
sbx.files.write("/home/user/image.png", f.read())
import { Sandbox } from "@declaw/sdk";
import { readFileSync } from "node:fs";
const sbx = await Sandbox.connect("sbx-a1b2c3d4", {
apiKey: "YOUR_API_KEY",
domain: "api.declaw.ai",
});
// Pass a Uint8Array — the SDK routes to /files/raw for binary payloads.
const bytes = new Uint8Array(readFileSync("image.png"));
await sbx.files.write("/home/user/image.png", bytes);
When to use this vs. other endpoints
| Payload | Use |
|---|---|
| UTF-8 text, < 10 MiB | POST /files (JSON) |
| Binary (any size up to 500 MiB) | PUT /files/raw (this endpoint) |
| Very large payloads (hundreds of MB, GB-class) | sbx.upload_url(path) / sbx.download_url(path) helpers |
Error Responses
| Status | Cause |
|---|---|
400 | Missing path query parameter |
401 | Missing or invalid API key |
404 | Sandbox not found |
409 | Sandbox is paused — resume it before accessing files |
410 | Sandbox has been killed |
413 | Request body exceeds 500 MiB |
502 | envd daemon unreachable |
503 | Sandbox has no VM |