Skip to main content
Read and write files inside a running sandbox. See Filesystem for usage examples.

SandboxFsOps

fs.read()

Read the entire contents of a file as raw bytes.

Parameters

pathstring
Absolute path inside the guest (e.g. “/app/config.json”).

Returns

Promise<Uint8Array>
File contents as raw bytes.

fs.readToString()

Read the entire contents of a file and decode it as UTF-8.

Parameters

pathstring
Absolute path inside the guest.

Returns

Promise<string>
File contents as a string.

fs.write()

Write content to a file, creating it if it doesn’t exist and overwriting if it does. Parent directories must already exist. string payloads are encoded as UTF-8.

Parameters

pathstring
Absolute path inside the guest.
dataUint8Array | string
File content. Strings are written as UTF-8.

fs.readStream()

Open a streaming reader for a file. Data is transferred in chunks. Use this for files too large to fit in memory. The returned FsReadStream is an AsyncIterable<Uint8Array>, so it works with for await...of.

Parameters

pathstring
Absolute path inside the guest.

Returns

Async stream that yields chunks of file data.

fs.writeStream()

Open a streaming writer for a file. Use this for files too large to hold in memory; pair with await using so the FsWriteSink closes itself when the scope exits.

Parameters

pathstring
Absolute path inside the guest.

Returns

Streaming writer.

fs.list()

List the entries in a directory.

Parameters

pathstring
Absolute directory path inside the guest.

Returns

Directory entries.

fs.mkdir()

Create a directory. Parent directories must already exist.

Parameters

pathstring
Absolute directory path.

fs.removeDir()

Remove a directory.

Parameters

pathstring
Absolute directory path.

fs.remove()

Remove a file.

Parameters

pathstring
Absolute file path.

fs.stat()

Get detailed metadata for a file or directory.

Parameters

pathstring
Absolute path inside the guest.

Returns

File metadata.

fs.exists()

Check whether a path exists inside the sandbox.

Parameters

pathstring
Absolute path inside the guest.

Returns

Promise<boolean>
true if the path exists.

fs.copy()

Copy a file within the sandbox.

Parameters

fromstring
Source path.
tostring
Destination path.

fs.rename()

Rename or move a file or directory within the sandbox.

Parameters

fromstring
Current path.
tostring
New path.

fs.copyFromHost()

Copy a file from the host machine into the sandbox. For transferring many files, consider a bind-mounted volume instead.

Parameters

hostPathstring
Path on the host filesystem.
guestPathstring
Destination path inside the sandbox.

fs.copyToHost()

Copy a file from the sandbox to the host machine.

Parameters

guestPathstring
Path inside the sandbox.
hostPathstring
Destination path on the host.

FsReadStream

Returned by readStream()

Async stream for reading a file in chunks. Implements AsyncIterable<Uint8Array> and AsyncDisposable, so it works with for await...of and await using.

stream.recv()

Receive the next chunk. Returns null when the file has been fully read.

Returns

Promise<Uint8Array \| null>

stream.collect()

Drain the stream into a single buffer

Returns

Promise<Uint8Array>

stream.Symbol.asyncIterator

Iterate chunks with for await...of

Returns

AsyncIterator<Uint8Array>

stream.Symbol.asyncDispose

Stop reading; runs on await using scope exit

Returns

Promise<void>

FsWriteSink

Returned by writeStream()

Streaming writer for a file. Implements AsyncDisposable, so it can be paired with await using.

sink.write()

Append a chunk. Strings are encoded as UTF-8.

Returns

Promise<void>

sink.close()

Flush and close. Idempotent.

Returns

Promise<void>

sink.Symbol.asyncDispose

Calls close() on await using scope exit

Returns

Promise<void>

Types

FsEntry

Returned by list()

Metadata for a single directory entry.

FsMetadata

Returned by stat()

Detailed file metadata.

FsEntryKind

Used by FsEntry.kind · FsMetadata.kind