Skip to main content
The sbx.files.write() API accepts both strings and raw bytes. When you pass bytes (Python) or Uint8Array (TypeScript), the SDK automatically routes the payload to the binary-safe PUT /files/raw endpoint (Content-Type: application/octet-stream, 500 MiB cap) instead of the text-only JSON endpoint. Callers pass whatever type they have — no manual base64 dance required.

What You’ll Learn

  • Writing raw bytes with sbx.files.write(path, b"...")
  • Reading bytes back with format="bytes" and verifying byte-identical round-trip
  • Writing real binary formats (a PNG) and proving the sandbox can decode them
  • The base64.b64decode(...)files.write(...) pattern common in LLM tool-use pipelines
  • Mixed batch writes — WriteEntry entries with str and bytes data in a single write_files() call

Prerequisites

Code Walkthrough

Random binary blob — the classic round-trip test:
Real PNG — write it, then let the sandbox decode it:
Base64-decoded payload — the LLM tool-use pattern:
Mixed batch — str and bytes entries in a single call. The SDK partitions entries internally (str → JSON batch, bytes → raw PUT) and returns results in the original input order:

When to use the URL helpers instead

/files/raw caps request bodies at 500 MiB, but the JSON gateway in front caps the text endpoint at 10 MiB. For very large uploads (hundreds of MB or GB-class), prefer sbx.upload_url(path) and sbx.download_url(path) — they return URLs your client can PUT/GET streams against directly.

Expected Output (Python)