sandbox.fs(). See Filesystem for usage examples. For bulk transfers, consider a bind-mounted volume instead.
Typical flow
SandboxFsOps
Filesystem handle for a running sandbox, obtained viasandbox.fs(). Every method is async and returns a Promise. Paths are absolute inside the guest.
fs.read()
Example
Example
Parameters
pathstringAbsolute path inside the guest (e.g.
“/app/config.json”).Returns
Promise<Uint8Array>
File contents as raw bytes.
fs.readToString()
Example
Example
Parameters
pathstringAbsolute path inside the guest.
Returns
Promise<string>
File contents as a string.
fs.write()
Example
Example
string payloads are encoded as UTF-8.
Parameters
pathstringAbsolute path inside the guest.
dataUint8Array | stringFile content. Strings are written as UTF-8.
fs.readStream()
Example
Example
FsReadStream is an AsyncIterable<Uint8Array>, so it works with for await...of.
Parameters
pathstringAbsolute path inside the guest.
Returns
Async stream that yields chunks of file data.
fs.writeStream()
Example
Example
await using so the FsWriteSink closes itself when the scope exits.
Parameters
pathstringAbsolute path inside the guest.
Returns
Streaming writer.
fs.list()
Example
Example
Parameters
pathstringAbsolute directory path inside the guest.
Returns
Directory entries.
fs.mkdir()
Example
Example
Parameters
pathstringAbsolute directory path.
fs.removeDir()
Example
Example
Parameters
pathstringAbsolute directory path.
fs.remove()
Example
Example
Parameters
pathstringAbsolute file path.
fs.stat()
Example
Example
Parameters
pathstringAbsolute path inside the guest.
Returns
File metadata.
fs.exists()
Example
Example
Parameters
pathstringAbsolute path inside the guest.
Returns
Promise<boolean>
true if the path exists.fs.copy()
Example
Example
Parameters
fromstringSource path.
tostringDestination path.
fs.rename()
Example
Example
Parameters
fromstringCurrent path.
tostringNew path.
fs.copyFromHost()
Example
Example
Parameters
hostPathstringPath on the host filesystem.
guestPathstringDestination path inside the sandbox.
fs.copyToHost()
Example
Example
Parameters
guestPathstringPath inside the sandbox.
hostPathstringDestination path on the host.
Types
FsEntry
Returned by list()
Metadata for a single directory entry.| Field | Type | Description |
|---|---|---|
| path | string | Entry path |
| kind | FsEntryKind | Type of entry |
| size | number | File size in bytes |
| mode | number | Unix permission bits |
| modified | Date | null | Last modified timestamp, or null if unavailable |
FsMetadata
Returned by stat()
Detailed file metadata.| Field | Type | Description |
|---|---|---|
| kind | FsEntryKind | Type of entry |
| size | number | File size in bytes |
| mode | number | Unix permission bits |
| readonly | boolean | Whether the file is read-only |
| modified | Date | null | Last modified timestamp, or null if unavailable |
| created | Date | null | Creation timestamp, or null if unavailable |
FsEntryKind
Used by FsEntry.kind · FsMetadata.kind
| Value | Description |
|---|---|
"file" | Regular file |
"directory" | Directory |
"symlink" | Symbolic link |
"other" | Other entry type |
FsReadStream
Returned by readStream()
Async stream for reading a file in chunks. ImplementsAsyncIterable<Uint8Array> and AsyncDisposable, so it works with for await...of and await using.
| Method | Returns | Description |
|---|---|---|
recv() | Promise<Uint8Array | null> | Receive the next chunk. Returns null when the file has been fully read. |
collect() | Promise<Uint8Array> | Drain the stream into a single buffer |
[Symbol.asyncIterator]() | AsyncIterator<Uint8Array> | Iterate chunks with for await...of |
[Symbol.asyncDispose]() | Promise<void> | Stop reading; runs on await using scope exit |
FsWriteSink
Returned by writeStream()
Streaming writer for a file. ImplementsAsyncDisposable, so it can be paired with await using.
| Method | Parameters | Returns | Description |
|---|---|---|---|
write(data) | Uint8Array | string | Promise<void> | Append a chunk. Strings are encoded as UTF-8. |
close() | - | Promise<void> | Flush and close. Idempotent. |
[Symbol.asyncDispose]() | - | Promise<void> | Calls close() on await using scope exit |