Skip to main content
Capture the disk state of a stopped sandbox into a portable artifact, then boot fresh sandboxes from it. See Snapshots for concepts and walkthroughs.
Snapshots are disk-only and require a sandbox that is not running (stopped or crashed).

Typical flow

Capture and boot

These entry points live on SandboxBuilder and SandboxHandle; they are the bridge between sandboxes and snapshot artifacts.

.fromSnapshot()

Boot a fresh sandbox from a snapshot artifact. Mutually exclusive with .image(); the snapshot already pins the image. Documented in full on the Sandbox page.

Parameters

pathOrNamestring
Bare name (resolved under the default snapshots directory) or filesystem path to an artifact directory.

Returns

The same builder, for chaining.

handle.snapshot()

Snapshot this sandbox under a bare name in the default snapshots directory (~/.microsandbox/snapshots/<name>/). Called on a SandboxHandle. The sandbox must be stopped or crashed; running sandboxes are rejected with a SnapshotSandboxRunning error. To place the artifact elsewhere, use Snapshot.save() / Snapshot.load() or move the self-contained artifact directory.

Parameters

namestring
Bare name; becomes the artifact directory under the default snapshots dir.

Returns

The created snapshot artifact.

Snapshot static methods

Snapshot.builder()

Begin building a new snapshot named name, resolved under the default snapshots directory (~/.microsandbox/snapshots/<name>/) or under .destDir() when set. The fluent builder is what powers the CLI internally. The source sandbox is set with .fromSandbox(), which is required. See SnapshotBuilder for all setters.

Parameters

namestring
Bare snapshot name; becomes the artifact directory under the default snapshots dir.

Returns

Builder for configuring the snapshot.

Snapshot.open()

Open an existing snapshot artifact. Bare names resolve under the default snapshots directory; anything else is treated as a path. Cheap metadata validation only; it does not read the upper file. Use verify() for content checks.

Parameters

pathOrNamestring
Bare name (resolved under the default snapshots dir) or filesystem path.

Returns

The opened snapshot.

Snapshot.get()

Look up an indexed snapshot by digest, name, or path. Returns a lightweight SnapshotHandle backed by the local index row.

Parameters

nameOrDigeststring
Name, digest (sha256:…), or path of an indexed snapshot.

Returns

Index-backed handle.

Snapshot.list()

List indexed snapshots from the local DB cache.

Returns

All indexed snapshot handles.

Snapshot.listDir()

Walk a directory and parse each subdirectory’s manifest. Does not touch the index, which makes it useful for inspecting external snapshot collections that were never loaded. Skips entries that don’t look like snapshot artifacts.

Parameters

dirstring
Directory to scan for artifact subdirectories.

Returns

Parsed snapshots found in the directory.

Snapshot.remove()

Remove a snapshot by path, name, or digest. Refuses if the snapshot has indexed children unless force is set.

Parameters

pathOrNamestring
Path, name, or digest of the snapshot to remove.
opts.forceboolean
Remove even if the snapshot has indexed children. Defaults to false.

Snapshot.reindex()

Walk the snapshots directory (default: the configured snapshots dir) and rebuild the local index. Returns the number of artifacts indexed.

Parameters

dirstring
Directory to scan. Defaults to the configured snapshots dir.

Returns

Promise<number>
Count of artifacts indexed.

Snapshot.save()

staticasync
Bundle a snapshot into a .tar.zst archive. The recorded manifest is archived as-is, so create the snapshot with recordIntegrity() if receivers must verify content. See SaveOpts for bundling options.

Parameters

nameOrPathstring
Name or path of the snapshot to bundle.
outstring
Output archive path.
Bundling options. All fields default to false.

Snapshot.load()

staticasync
Unpack a snapshot archive (.tar.zst or .tar) into the snapshots directory, verifying recorded integrity on the way in. Compression is detected from magic bytes.

Parameters

archivestring
Path to the archive to unpack.
deststring
Destination directory. Defaults to the snapshots directory.

Returns

Handle to the loaded snapshot.

Snapshot instance members

A Snapshot is a snapshot artifact on disk. The artifact is a directory containing the snapshot.json descriptor and the captured upper.ext4. The directory is the source of truth; the local DB index is just a rebuildable cache. Returned by Snapshot.builder().create(), Snapshot.open(), and handle.snapshot().

snap.path

Path to the artifact directory.

snap.digest

Canonical content digest (sha256:hex). The snapshot’s identity.

snap.sizeBytes

Apparent size of the captured upper layer in bytes (sparse on disk).

snap.imageRef

Image reference the snapshot was taken from.

snap.imageManifestDigest

OCI manifest digest of the pinned image.

snap.format

On-disk format of the upper layer.

snap.scope

getter
Snapshot scope: "disk" for a disk-only snapshot, "resumable" once resumable snapshots land. Always "disk" today. See SnapshotScope.

snap.fstype

Filesystem type inside the upper (e.g. "ext4").

snap.parent

Manifest digest of the parent snapshot, or null for a root.

snap.createdAt

RFC 3339 timestamp when the snapshot was created.

snap.labels

User-supplied labels (sorted by key in canonical form), as [key, value] pairs.

snap.sourceSandbox

Best-effort source-sandbox name, if recorded. null when the manifest has no source recorded.

snap.verify()

Recompute the upper layer’s content hash and compare against the manifest. Walks data extents only, so a 4 GiB sparse file with a few MB of data verifies in milliseconds. The report’s upper.kind is "notRecorded" when the manifest has no integrity hash recorded.

Returns

Verification result.

SnapshotBuilder

Fluent builder for a snapshot, returned by Snapshot.builder(name). Every setter mutates in place and returns this, so calls chain. The source sandbox is required: call .fromSandbox() before .create().

.fromSandbox()

builder
Set the sandbox to capture. Required; .create() fails without it.

Parameters

sourceSandboxstring
Name of the stopped sandbox to capture.

.destDir()

builder
Create the artifact under this parent directory instead of the default snapshots store. The artifact directory is destDir/<name>; the name stays the snapshot’s identity either way.

Parameters

destDirstring
Parent directory to create the artifact in (e.g. a larger volume).

.label()

Add a key=value label to the snapshot manifest. May be called repeatedly.

Parameters

keystring
Label key.
valuestring
Label value.

.force()

Overwrite an existing artifact with the same name instead of failing on conflict.

.recordIntegrity()

Compute and record a content-integrity hash of the upper layer at creation time, so the snapshot can be verified later or across a trust boundary.

.resumable()

builder
Request a "resumable" snapshot (disk plus VM state). Accepted by the builder, but .create() currently returns an Unsupported error; resumable snapshots have not landed yet.

.create()

Capture the configured snapshot and return the resulting artifact.

Returns

The created snapshot artifact.

Types

SnapshotHandle class

Lightweight handle backed by an index row. Values are snapshotted from the index at construction time; call Snapshot.get() again for a fresh reading if needed. Handles from Snapshot.list() are read-only and throw on open() / remove(); fetch a live handle via Snapshot.get() for those lifecycle methods.

Returned by Snapshot.get(), Snapshot.list(), Snapshot.load()

snapshotHandle.open()

Open and metadata-validate the underlying artifact. Throws if this handle is read-only (came from Snapshot.list()); fetch a live handle via Snapshot.get() first.

snapshotHandle.remove()

Remove the artifact and its index row. Refuses if the snapshot has indexed children unless force is set. Throws if this handle is read-only.

SaveOpts interface

Bundle options for Snapshot.save(). All fields default to false.

Used by Snapshot.save()


SnapshotScope type

Scope of what a snapshot captures. Every snapshot today is "disk"; "resumable" (disk plus VM state) is reserved for resumable snapshots.

Returned by snap.scope · SnapshotHandle.scope


SnapshotVerifyReport union

Result of snap.verify(). The upper discriminant is "notRecorded" when no integrity hash was stored at create time, or "verified" when the recorded hash matched the recomputed one.

Returned by snap.verify()