Skip to main content
Create, manage, and mount named volumes. See Volumes for usage examples.

Volume

Instance properties

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.

Static methods

Volume.getDefault()

Get the Cloud account’s always-present default volume. It has no user-assigned name, cannot be removed, and supports direct filesystem operations through .fs(). The local backend returns a typed Unsupported error; it never substitutes a directory from the caller’s machine.

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.fs()

Get a filesystem handle for this volume. Local reads and writes use the managed host directory; Cloud reads and writes use the authenticated volume API. No sandbox needs to be 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.

volumeBuilder.directory()

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

volumeBuilder.disk()

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

volumeBuilder.size()

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

Parameters

mibnumber
Disk capacity in MiB.

volumeBuilder.quota()

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

Parameters

mibnumber
Quota in MiB.

volumeBuilder.label()

Add a metadata label. Can be called multiple times.

Parameters

keystring
Label key.
valuestring
Label value.

volumeBuilder.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.

volumeBuilder.create()

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

Returns

The created volume.

VolumeFs

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

Host-side filesystem operations for a named volume.

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.

VolumeHandle

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

A metadata and lifecycle handle for an existing volume.

handle.name

string Volume name

handle.kind

string Volume kind ("dir" or "disk")

handle.quotaMib

number \| null Recorded storage quota in MiB

handle.usedBytes

number Current disk usage in bytes

handle.capacityBytes

number \| null Disk capacity in bytes (disk volumes)

handle.diskFormat

string \| null Disk image format (disk volumes)

handle.diskFstype

string \| null Inner disk filesystem (disk volumes)

handle.labels

ReadonlyArray<readonly [string, string]> Metadata labels

handle.createdAt

Date \| null Creation timestamp

handle.fs()

Host-side filesystem (live handles only; throws on read-only handles)

Returns

VolumeFs

handle.remove()

Delete this volume (live handles only; throws on read-only handles)

Returns

Promise<void>

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.

stream.recv()

Read the next chunk; null when the stream is exhausted

Returns

Promise<Uint8Array \| null>

stream.collect()

Drain the stream into a single byte array

Returns

Promise<Uint8Array>

stream.Symbol.asyncIterator

Iterate chunks with for await

Returns

AsyncIterator<Uint8Array>

stream.Symbol.asyncDispose

Mark the stream done (for using)

Returns

Promise<void>

VolumeFsWriteSink

Returned by VolumeFs.writeStream()

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

sink.write()

Write a chunk (Uint8Array or UTF-8 string)

Returns

Promise<void>

sink.close()

Flush and close the sink; idempotent

Returns

Promise<void>

sink.Symbol.asyncDispose

Close the sink (for await using)

Returns

Promise<void>