Typical flow
sb.fs property on a running Sandbox. All methods are coroutines, so await each call.
Methods
fs.read()
Example
Example
Parameters
pathstrAbsolute path inside the guest, e.g.
“/app/config.json”.Returns
bytes
File contents as raw bytes.
fs.read_text()
Example
Example
Parameters
pathstrAbsolute path inside the guest.
Returns
str
File contents decoded as UTF-8.
fs.read_stream()
Example
Example
FsReadStream is an async iterator that yields chunks of bytes, or call its collect() to gather everything into one bytes.
Parameters
pathstrAbsolute path inside the guest.
Returns
Async iterator yielding chunks of file data.
fs.write()
Example
Example
Parameters
pathstrAbsolute path inside the guest.
databytesFile content.
fs.write_stream()
Example
Example
FsWriteSink supports the async context manager protocol, so async with closes and finalizes the file automatically.
Parameters
pathstrAbsolute path inside the guest.
Returns
Async writer that accepts chunks of bytes.
fs.list()
Example
Example
Parameters
pathstrAbsolute directory path inside the guest.
Returns
Directory entries.
fs.mkdir()
Example
Example
Parameters
pathstrAbsolute directory path inside the guest.
fs.stat()
Example
Example
Parameters
pathstrAbsolute path inside the guest.
Returns
File metadata.
fs.exists()
Example
Example
Parameters
pathstrAbsolute path inside the guest.
Returns
bool
True if the path exists.fs.remove_dir()
Example
Example
Parameters
pathstrAbsolute directory path inside the guest.
fs.copy()
Example
Example
Parameters
srcstrSource path inside the guest.
dststrDestination path inside the guest.
fs.rename()
Example
Example
Parameters
srcstrCurrent path inside the guest.
dststrNew path inside the guest.
fs.remove()
Example
Example
remove_dir() for directories.
Parameters
pathstrAbsolute file path inside the guest.
fs.copy_from_host()
Example
Example
Parameters
host_pathstrPath on the host filesystem.
guest_pathstrDestination path inside the sandbox.
fs.copy_to_host()
Example
Example
Parameters
guest_pathstrPath inside the sandbox.
host_pathstrDestination path on the host.
Types
FsEntry
Returned by list()
Metadata for a single directory entry, returned bylist().
| Property | Type | Description |
|---|---|---|
| path | str | Full path of the entry |
| kind | str | Entry type: "file", "directory", "symlink", or "other" (see FsEntryKind) |
| size | int | File size in bytes |
| mode | int | Unix permission bits |
| modified | float | None | Last-modified time, milliseconds since the Unix epoch |
FsEntryKind
Describes FsEntry.kind · FsMetadata.kind
String enum (StrEnum) of filesystem entry types. The kind fields on FsEntry and FsMetadata carry these string values.
| Value | Description |
|---|---|
"file" | Regular file |
"directory" | Directory |
"symlink" | Symbolic link |
"other" | Other entry type |
FsMetadata
Returned by stat()
Detailed file metadata, returned bystat().
| Property | Type | Description |
|---|---|---|
| kind | str | Entry type: "file", "directory", "symlink", or "other" (see FsEntryKind) |
| size | int | File size in bytes |
| mode | int | Unix permission bits |
| readonly | bool | Whether the file is read-only |
| modified | float | None | Last-modified time, milliseconds since the Unix epoch |
| created | float | None | Creation time, milliseconds since the Unix epoch |
FsReadStream
Returned by read_stream()
Async stream for reading a file in chunks. Obtained viaread_stream(). Iterate it with async for chunk in stream:, or call collect() to gather everything at once.
| Method / Protocol | Returns | Description |
|---|---|---|
__aiter__ / __anext__ | bytes | Async iterator. Use async for chunk in stream:. |
| collect() | bytes | (async) Collect all remaining data into a single bytes object |
FsWriteSink
Returned by write_stream()
Async writer for streaming data into a file. Obtained viawrite_stream(). Supports the async context manager protocol, so async with closes the sink on exit.
| Method / Protocol | Returns | Description |
|---|---|---|
| write(data) | None | (async) Write a chunk of bytes to the file |
| close() | None | (async) Send EOF and finalize the file |
__aenter__ / __aexit__ | FsWriteSink | (async) Use with async with for automatic close on exit |