Skip to main content
Read and write files in a sandbox’s filesystem with sandbox.files.

write

Write a file at an absolute path. Parent directories are created automatically.
Parameters: Accepted content types:
Cancellation (TypeScript):

read

Read a file as raw bytes.

readText / read_text

Read a file and decode as UTF-8.

downloadDir / download_dir

Download a directory as a ZIP archive. Returns the raw zip bytes — entries are prefixed with the directory’s base name (e.g. output/log.txt), and symlinks are skipped.
Parameters: The server decides file-vs-directory: if path points at a regular file, its bytes are streamed back as-is (not zipped) — use read for files.

Round-trip example

Path rules

  • Paths must start with /
  • Paths must not contain .. segments
  • Parent directories are created automatically on write

Errors

Commonly raised:
  • NotFoundError - file or directory does not exist (on read / downloadDir)
  • ValidationError - invalid path (relative, contains .., or malformed)
  • AuthenticationError - access token invalid or sandbox was deleted
  • TimeoutError / SandboxTimeoutError - the optional timeout elapsed
See Errors for the full hierarchy.