Skip to main content
Create and manage named volumes: persistent storage that lives independently of any sandbox. Build a volume, look one up, read and write its files from the host, then delete it. See Volumes for usage examples and patterns.

Typical flow

Static methods

Volume.builder()

Begin building a named volume. Directory-backed volumes are the default. Call .disk().size(...) for a disk-backed volume. See VolumeBuilder for all options.

Parameters

namestring
Volume name.

Returns

Fluent builder for configuring the volume.

Volume.get()

Get a live handle to an existing named volume. A live handle supports .fs() and .remove(), unlike the read-only handles returned by list().

Parameters

namestring
Volume name.

Returns

Live handle with metadata, filesystem access, and removal.

Volume.list()

List all named volumes. Handles returned here are read-only: calling .fs() or .remove() on them throws. Call Volume.get(name) to upgrade to a live handle.

Returns

All volumes, as read-only handles.

Volume.remove()

Delete a named volume and its contents. Fails if the volume is currently mounted by a sandbox.

Parameters

namestring
Volume name.

Instance methods

volume.name

The volume’s name.

Returns

string
Volume name.

volume.path

Absolute host path to the volume’s directory. By default volumes live under ~/.microsandbox/volumes/<name>/.

Returns

string
Absolute host directory path.

volume.fs()

Get a host-side filesystem handle for this volume’s directory. Reads and writes happen directly on the host, with no sandbox running. See VolumeFs for the full API.

Returns

Host-side filesystem handle.

VolumeBuilder

Fluent builder for a named volume. Obtained via Volume.builder(name). Directory-backed volumes are the default; call disk() plus size() for a disk-backed volume. Every setter returns the builder, so calls chain.

.directory()

Create a directory-backed volume. This is the default, so calling it is only needed for clarity.

.disk()

Create a raw ext4 disk-backed volume. Pair with size() to set the capacity.

.size()

Set the disk capacity in MiB. Required after disk().

Parameters

mibnumber
Disk capacity in MiB.

.quota()

Record a quota in MiB as metadata for directory-backed volumes.

Parameters

mibnumber
Quota in MiB.

.label()

Add a metadata label. Can be called multiple times.

Parameters

keystring
Label key.
valuestring
Label value.

.build()

Materialize the volume configuration without creating the volume on disk. To create it, use create() instead. The returned config object is the internal NapiVolumeConfig shape (not a public export).

Returns

Frozen volume configuration object.

.create()

Build and create the volume on disk, returning a Volume.

Returns

The created volume.

VolumeFs methods

Host-side filesystem operations on a volume’s directory. Obtained via volume.fs() or VolumeHandle.fs(). All operations run directly on the host without booting a sandbox. Paths are relative to the volume’s root directory. Every method is async.

vfs.read()

Read a file’s full contents as bytes.

Parameters

pathstring
Path relative to the volume root.

Returns

Promise<Uint8Array>
File contents.

vfs.readToString()

Read a file’s full contents as a UTF-8 string.

Parameters

pathstring
Path relative to the volume root.

Returns

Promise<string>
Decoded file contents.

vfs.readStream()

Open a streaming reader for a file, for chunked reads of large files without loading them fully into memory.

Parameters

pathstring
Path relative to the volume root.

Returns

Async-iterable read stream.

vfs.write()

Write a file, replacing any existing contents. Strings are encoded as UTF-8.

Parameters

pathstring
Path relative to the volume root.
dataUint8Array | string
Bytes, or a UTF-8 string.

vfs.writeStream()

Open a streaming writer for a file, for chunked writes of large files.

Parameters

pathstring
Path relative to the volume root.

Returns

Write sink; call close() when done.

vfs.list()

List the entries in a directory. Pass "" for the volume root.

Parameters

pathstring
Directory path relative to the volume root.

Returns

Directory entries.

vfs.mkdir()

Create a directory, including any missing parents.

Parameters

pathstring
Directory path relative to the volume root.

vfs.removeDir()

Recursively remove a directory and its contents.

Parameters

pathstring
Directory path relative to the volume root.

vfs.remove()

Remove a single file.

Parameters

pathstring
File path relative to the volume root.

vfs.copy()

Copy a file or directory from one path to another.

Parameters

fromstring
Source path relative to the volume root.
tostring
Destination path relative to the volume root.

vfs.rename()

Move or rename a file or directory.

Parameters

fromstring
Source path relative to the volume root.
tostring
Destination path relative to the volume root.

vfs.stat()

Get metadata for a file or directory.

Parameters

pathstring
Path relative to the volume root.

Returns

Kind, size, mode, and timestamps.

vfs.exists()

Check whether a path exists.

Parameters

pathstring
Path relative to the volume root.

Returns

Promise<boolean>
true if the path exists.

Types

VolumeHandle

Returned by Volume.get() · Volume.list()

A handle to an existing named volume, carrying its metadata. Handles from Volume.get() are live: .fs() and .remove() work. Handles in the array from Volume.list() are read-only: those two methods throw, so call Volume.get(name) to upgrade.

VolumeFs

Returned by volume.fs() · VolumeHandle.fs()

Host-side filesystem operations on a volume’s directory. The methods mirror SandboxFsOps but run directly on the host with no sandbox booted. See the VolumeFs methods section above for full per-method details.

VolumeFsReadStream

Returned by VolumeFs.readStream()

A streaming reader over a volume file. Implements AsyncIterable<Uint8Array> and AsyncDisposable, so it works with for await and using.

VolumeFsWriteSink

Returned by VolumeFs.writeStream()

A streaming writer for a volume file. Implements AsyncDisposable, so await using closes it automatically.