Filesystem module provides full file I/O within a sandbox. Access it via sandbox.files.
Reading Files
await sandbox.files.read(path)
Reads a file as a UTF-8 string.
Absolute path to the file.
str
await sandbox.files.read_bytes(path)
Reads a file as raw bytes.
Absolute path to the file.
bytes
Writing Files
await sandbox.files.write(path, content)
Writes a string or bytes to a file. Creates parent directories if needed.
Absolute path to the file.
File content to write.
None
Listing Directories
await sandbox.files.list(path)
Lists the contents of a directory.
Directory path to list.
list[EntryInfo]
EntryInfo
EntryInfo is a dataclass:
| Field | Type | Description |
|---|---|---|
name | str | File or directory name |
is_dir | bool | True if this entry is a directory |
path | str | Full path to the entry |
size | int | Size in bytes (0 for directories) |
Managing Files and Directories
await sandbox.files.make_dir(path)
Creates a directory and any necessary parent directories.
Directory path to create.
None
await sandbox.files.remove(path)
Deletes a file or directory.
Path to remove.
None
await sandbox.files.exists(path)
Checks whether a file or directory exists.
Path to check.
bool