Snapshots are disk-only and require a sandbox that is not running (stopped or crashed).
Typical flow
Capture and boot
These entry points live onSandboxBuilder and SandboxHandle; they are the bridge between sandboxes and snapshot artifacts.
.fromSnapshot()
Example
Example
.image(); the snapshot already pins the image. Documented in full on the Sandbox page.
Parameters
pathOrNamestringBare name (resolved under the default snapshots directory) or filesystem path to an artifact directory.
Returns
The same builder, for chaining.
handle.snapshot()
Example
Example
~/.microsandbox/snapshots/<name>/). Called on a SandboxHandle. The sandbox must be stopped or crashed; running sandboxes are rejected with a SnapshotSandboxRunning error. For an explicit filesystem destination, see snapshotTo().
Parameters
namestringBare name; becomes the artifact directory under the default snapshots dir.
Returns
The created snapshot artifact.
handle.snapshotTo()
Example
Example
SandboxHandle. The sandbox must be stopped or crashed.
Parameters
pathstringDestination artifact directory path.
Returns
The created snapshot artifact.
Snapshot static methods
Snapshot.builder()
Example
Example
sourceSandbox (which must be stopped). The fluent builder is what powers the CLI internally. The bare-name and explicit-path destinations are mutually exclusive: call exactly one of .name() or .path(). See SnapshotBuilder for all setters.
Parameters
sourceSandboxstringName of the stopped sandbox to capture.
Returns
Builder for configuring the snapshot.
Snapshot.open()
Example
Example
verify() for content checks.
Parameters
pathOrNamestringBare name (resolved under the default snapshots dir) or filesystem path.
Returns
The opened snapshot.
Snapshot.get()
Example
Example
SnapshotHandle backed by the local index row.
Parameters
nameOrDigeststringName, digest (
sha256:…), or path of an indexed snapshot.Returns
Index-backed handle.
Snapshot.list()
Example
Example
Returns
All indexed snapshot handles.
Snapshot.listDir()
Example
Example
Parameters
dirstringDirectory to scan for artifact subdirectories.
Returns
Parsed snapshots found in the directory.
Snapshot.remove()
Example
Example
force is set.
Parameters
pathOrNamestringPath, name, or digest of the snapshot to remove.
opts.forcebooleanRemove even if the snapshot has indexed children. Defaults to
false.Snapshot.reindex()
Example
Example
Parameters
dirstringDirectory to scan. Defaults to the configured snapshots dir.
Returns
Promise<number>
Count of artifacts indexed.
Snapshot.export()
Example
Example
.tar.zst archive. When the snapshot has no integrity hash yet, one is computed and embedded in the bundled manifest so the receiver can verify. See ExportOpts for bundling options.
Parameters
nameOrPathstringName or path of the snapshot to bundle.
outstringOutput archive path.
optsExportOptsBundling options. All fields default to
false.Snapshot.import()
Example
Example
.tar.zst or .tar) into the snapshots directory, verifying recorded integrity on the way in. Compression is detected from magic bytes.
Parameters
archivestringPath to the archive to unpack.
deststringDestination directory. Defaults to the snapshots directory.
Returns
Handle to the imported snapshot.
Snapshot instance members
ASnapshot is a snapshot artifact on disk. The artifact is a directory containing manifest.json 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(), handle.snapshot(), and handle.snapshotTo().
snap.path
snap.digest
sha256:hex). The snapshot’s identity.
snap.sizeBytes
snap.imageRef
snap.imageManifestDigest
snap.format
snap.fstype
"ext4").
snap.parent
null for a root.
snap.createdAt
snap.labels
[key, value] pairs.
snap.sourceSandbox
null when the manifest has no source recorded.
snap.verify()
Example
Example
upper.kind is "notRecorded" when the manifest has no integrity hash recorded.
Returns
Verification result.
SnapshotBuilder
Fluent builder for a snapshot, returned bySnapshot.builder(name). Every setter mutates in place and returns this, so calls chain. Pick exactly one destination: .name() or .path().
.name()
.path().
Parameters
namestringBare snapshot name.
.path()
.name().
Parameters
pathstringDestination artifact directory path.
.label()
key=value label to the snapshot manifest. May be called repeatedly.
Parameters
keystringLabel key.
valuestringLabel value.
.force()
.recordIntegrity()
.create()
Example
Example
Returns
The created snapshot artifact.
Types
SnapshotHandle class
Lightweight handle backed by an index row. Values are snapshotted from the index at construction time; callSnapshot.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.import()
| Member | Type | Description |
|---|---|---|
digest | string | Manifest digest (sha256:hex), the canonical identity. |
name | string | null | Convenience name; null for digest-only entries. |
parentDigest | string | null | Parent snapshot’s manifest digest, or null for a root. |
imageRef | string | Image reference the snapshot was taken from. |
format | "raw" | "qcow2" | On-disk format of the upper layer. |
sizeBytes | bigint | null | Apparent size of the upper file at index time. |
createdAt | Date | Snapshot creation time (from manifest). |
path | string | Local artifact directory path. |
open() | Promise<Snapshot> | Open and metadata-validate the underlying artifact. |
remove(opts?) | Promise<void> | Remove the artifact and its index row; refuses on children unless force. |
snapshotHandle.open()
Snapshot.list()); fetch a live handle via Snapshot.get() first.
snapshotHandle.remove()
force is set. Throws if this handle is read-only.
ExportOpts interface
Bundle options forSnapshot.export(). All fields default to false.
Used by Snapshot.export()
| Field | Type | Description |
|---|---|---|
withParents | boolean | Walk the parent chain and include each ancestor (no-op in v1). |
withImage | boolean | Include the OCI image cache so the archive boots offline. |
plainTar | boolean | Skip zstd compression and write a plain .tar. |
SnapshotVerifyReport union
Result ofsnap.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()
| Field | Type | Description |
|---|---|---|
digest | string | Snapshot’s manifest digest. |
path | string | Artifact directory path. |
upper.kind | "notRecorded" | "verified" | Whether an integrity hash was recorded and checked. |
upper.algorithm | string | Hash algorithm ("verified" only). |
upper.digest | string | Recomputed upper-layer digest ("verified" only). |