Skip to main content
sbx.files is the Filesystem sub-module available on every Sandbox instance. All paths must be absolute paths within the sandbox filesystem.

sbx.files.read()

Read a file’s content from the sandbox.
str
required
Absolute path inside the sandbox.
str
default:"'text'"
Output format. One of "text" (returns str), "bytes" (returns bytearray), or "stream" (returns Iterator[bytes]).
str
default:"'user'"
Unix user context for the read operation.
float | None
default:"None"
Per-request HTTP timeout in seconds.
Returns str | bytearray | Iterator[bytes]

sbx.files.write()

Write content to a file. Creates parent directories automatically.

Binary writes

Pass bytes (or any file-like object containing binary data) and the SDK routes the payload to the binary-safe PUT /files/raw endpoint automatically — no manual base64 encoding required.
bytes payloads are capped at 500 MiB per request. For larger uploads, use sbx.upload_url() to get a streaming URL.
str
required
Absolute path inside the sandbox. Parent directories are created if they do not exist.
str | bytes | IO
required
Content to write. str is sent via the JSON POST /files endpoint (10 MiB cap). bytes or a file-like object is streamed to PUT /files/raw (500 MiB cap). The SDK dispatches based on payload type — callers do not need to pick the transport.
str
default:"'user'"
Unix user context.
float | None
default:"None"
Per-request HTTP timeout in seconds.
Returns WriteInfo

sbx.files.write_files()

Write multiple files in a single batch request. More efficient than calling write() in a loop.
data may be str or bytes. The SDK partitions entries internally — string entries go through the JSON batch endpoint in a single request, bytes entries are streamed individually to PUT /files/raw — and returns results in the original input order.
list[WriteEntry]
required
List of WriteEntry objects. Each has path (str) and data (str or bytes).
str
default:"'user'"
Unix user context applied to all files.
float | None
default:"None"
Per-request HTTP timeout in seconds.
Returns list[WriteInfo]

sbx.files.list()

List the contents of a directory.
str
required
Absolute path to the directory.
int | None
default:"1"
Recursion depth. 1 lists only the immediate children of the directory. None or a larger value recurses deeper.
str
default:"'user'"
Unix user context.
float | None
default:"None"
Per-request HTTP timeout in seconds.
Returns list[EntryInfo]

sbx.files.exists()

Check whether a file or directory exists.
str
required
Absolute path to check.
str
default:"'user'"
Unix user context.
float | None
default:"None"
Per-request HTTP timeout in seconds.
Returns bool

sbx.files.get_info()

Get metadata about a single file or directory entry.
str
required
Absolute path to query.
str
default:"'user'"
Unix user context.
float | None
default:"None"
Per-request HTTP timeout in seconds.
Returns EntryInfo

sbx.files.remove()

Remove a file or directory.
str
required
Absolute path to remove.
str
default:"'user'"
Unix user context.
float | None
default:"None"
Per-request HTTP timeout in seconds.
Returns None

sbx.files.rename()

Rename or move a file or directory.
str
required
Current absolute path.
str
required
New absolute path. Can be a different directory (move semantics).
str
default:"'user'"
Unix user context.
float | None
default:"None"
Per-request HTTP timeout in seconds.
Returns EntryInfo for the renamed entry.

sbx.files.make_dir()

Create a directory (including parent directories if needed).
str
required
Absolute path of the directory to create.
str
default:"'user'"
Unix user context.
float | None
default:"None"
Per-request HTTP timeout in seconds.
Returns boolTrue if the directory was created.

sbx.files.watch_dir()

Watch a directory for filesystem events. Returns a WatchHandle that receives events from the sandbox.
str
required
Absolute path of the directory to watch.
str
default:"'user'"
Unix user context.
float | None
default:"None"
Per-request HTTP timeout in seconds.
bool
default:"False"
Watch the directory and all subdirectories recursively.
Returns WatchHandle

Data models

EntryInfo

FileType

WriteInfo

WriteEntry

FilesystemEvent

FilesystemEventType

WatchHandle

The handle uses a poll-and-drain model — call get_new_events() to pull buffered events. There is no iterator protocol or callback subscription.

Examples

Upload and execute a script

Batch upload a dataset

Download generated output