Skip to main content
Create and manage disk-only snapshots of stopped sandboxes. See Snapshots for usage and lifecycle concepts.

Snapshot

Snapshot::builder()

Start configuring a new snapshot named name, resolved under the default snapshots directory (~/.microsandbox/snapshots/<name>/) or under dest_dir() when set. The source sandbox is set with from_sandbox(), which is required; the other setters cover labels and whether to record content integrity before capturing. See SnapshotBuilder for all options.

Parameters

nameimpl Into<String>
Bare snapshot name. Must not be empty, contain /, or start with ..

Returns

Builder for configuring the snapshot.

Snapshot::create()

Create a snapshot artifact from a stopped sandbox. Writes the snapshot.json descriptor and the captured upper.ext4 into the artifact directory atomically (the descriptor is renamed into place last), then best-effort upserts a row into the local index. Index failures are logged but do not fail the call; the artifact is the source of truth. Most callers use the builder’s create() instead of constructing a SnapshotConfig by hand.

Parameters

Name, source sandbox, labels, and integrity flag.

Returns

The created artifact handle.

Snapshot::open()

Open an existing artifact by path or bare name. Bare names (no path separator, not starting with . or ~) resolve under the default snapshots directory; anything else is treated as a path. This is a fast metadata operation: it verifies the manifest structure, recomputes the manifest digest, and checks that the upper file exists with the recorded size. It does not read the full upper contents; use verify() for that.

Parameters

path_or_nameimpl AsRef<str>
Bare snapshot name or filesystem path to an artifact directory.

Returns

The opened artifact handle.

Snapshot::get()

Look up a lightweight SnapshotHandle in the local index by name, digest (sha256:/sha512: prefix), or path.

Parameters

name_or_digest&str
Snapshot name, manifest digest, or artifact path.

Returns

Handle backed by the matching index row.

Snapshot::list()

List indexed snapshots from the local DB cache, newest first. External-path artifacts booted by full path aren’t in the index and won’t appear here; use list_dir to enumerate artifacts on disk directly.

Returns

Indexed snapshot handles, ordered by creation time descending.

Snapshot::list_dir()

Walk a directory and parse each subdirectory’s manifest. Does not touch the index. Skips entries that don’t look like snapshot artifacts (no snapshot.json) and malformed artifacts.

Parameters

dirimpl AsRef<Path>
Directory to scan for artifacts.

Returns

One handle per valid artifact found.

Snapshot::remove()

Remove a snapshot artifact (by digest, name, or path) and its index row. Refuses if the snapshot has indexed children unless force is set. The artifact directory is deleted on success and the parent’s child count is decremented.

Parameters

path_or_name&str
Snapshot digest, name, or artifact path.
forcebool
When true, remove even if the snapshot has indexed children.

Snapshot::reindex()

Rebuild the local index from the artifacts in dir. Upserts an index row for every artifact found, then recomputes parent-edge child counts in one pass so the cache stays honest about the current set of artifacts.

Parameters

dirimpl AsRef<Path>
Directory of artifacts to index.

Returns

usize
Number of artifacts indexed.

Snapshot::save()

staticasync
Bundle a snapshot into a .tar.zst archive (or plain .tar) at out. Recorded payload integrity is preserved but not executed implicitly; call verify() when an independent content scan is part of your workflow. See SaveOpts to also include ancestors and the OCI image cache.

Parameters

name_or_path&str
Snapshot name or artifact path to save.
out&Path
Output archive path. Parent directories are created if missing.
Bundling options. SaveOpts::default() writes the head snapshot only, zstd-compressed.

Snapshot::load()

staticasync
Unpack a snapshot archive (.tar.zst or .tar, detected from magic bytes) into the snapshots directory (or dest), routing any bundled image-cache entries into the global cache and registering everything found in the index. Structural and archive-entry checks remain mandatory, while recorded payload integrity is preserved for explicit verify(). Returns a handle for the head snapshot.

Parameters

archive_path&Path
Archive to unpack.
destOption<&Path>
Destination directory. None uses the default snapshots directory.

Returns

Handle for the head (last-listed) snapshot.

Instance methods

Methods on an opened Snapshot artifact.

snap.digest()

Canonical content digest of this snapshot’s manifest (sha256:hex). This is the snapshot’s identity.

Returns

&str
Manifest digest in sha256:hex form.

snap.path()

Path to the artifact directory holding the canonical snapshot.json descriptor and the captured upper file.

Returns

&Path
Artifact directory path.

snap.manifest()

The parsed Manifest: schema, format, fstype, image reference, parent, creation time, labels, and upper-layer metadata.

Returns

Parsed snapshot manifest.

snap.size_bytes()

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

Returns

u64
Upper-layer apparent size in bytes.

snap.verify()

Recompute the upper layer’s recorded content integrity and compare it against the descriptor. Current BLAKE3 Merkle integrity skips known all-hole subtrees and hashes allocated leaves in batches. Released SHA algorithms retain their exact verifier and may still cost O(logical size). Returns NotRecorded without reading payload contents when the descriptor has integrity: null; errors with SnapshotIntegrity on mismatch.

Returns

Digest, path, and upper-layer verification status.

SnapshotHandle

struct

Returned by Snapshot::get() · Snapshot::list() · Snapshot::load()

A snapshot handle backed by the local index.

h.digest()

Manifest digest (sha256:hex), the canonical identity.

h.name()

Name alias, or None for digest-only entries.

h.parent_digest()

The parent snapshot’s digest, or None for a root. Always None today; populated once chained snapshots land.

h.scope()

instance
Snapshot payload scope: SnapshotScope::Disk for a disk-only snapshot, Resumable once resumable snapshots land. Always Disk today.

h.image_ref()

Image reference the snapshot was taken from.

h.format()

On-disk format of the upper layer.

Returns

Upper-layer format (Raw today).

h.size_bytes()

Apparent size of the upper file at index time, if recorded.

h.created_at()

Snapshot creation time, parsed from the manifest.

h.path()

Local artifact directory path.

h.open()

Open the underlying artifact metadata, upgrading this lightweight handle to a full Snapshot. Equivalent to Snapshot::open(self.path()).

Returns

The opened artifact.

h.remove()

Remove this snapshot. Delegates to Snapshot::remove(self.digest(), force).

Parameters

forcebool
When true, remove even if the snapshot has indexed children.

SandboxBuilder

Snapshot-related methods that live on the sandbox builder and handle. See Sandbox for the full sandbox API.

sandbox.from_snapshot()

SandboxBuilder setter. Boot a fresh sandbox from a snapshot artifact. The snapshot already pins the image reference and digest, so this is mutually exclusive with image() and image_with(). The artifact is structurally opened at create() time; persistent payload integrity is checked only through explicit Snapshot::verify().

Parameters

path_or_nameimpl Into<String>
Bare name resolved under the default snapshots directory, or a path to an artifact directory.

SandboxHandle

h.snapshot()

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

Parameters

name&str
Bare snapshot name.

Returns

The created artifact handle.

h.snapshot_to()


SnapshotBuilder

Builder for snapshot configuration.

snapshot_builder.from_sandbox()

builder
Set the sandbox to capture. Required; build() and create() fail without it.

Parameters

source_sandboximpl Into<String>
Name of the source sandbox. Must be stopped or crashed, and rooted on an OCI image.

snapshot_builder.dest_dir()

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

Parameters

dest_dirimpl Into<PathBuf>
Parent directory to create the artifact in (e.g. a larger volume).

snapshot_builder.label()

Add a user label. Can be called multiple times. Labels are sorted by key in the manifest’s canonical form.

Parameters

keyimpl Into<String>
Label key.
valueimpl Into<String>
Label value.

snapshot_builder.force()

Overwrite an existing artifact with the same name. Without this, creation fails with SnapshotAlreadyExists if the artifact directory exists.

snapshot_builder.record_integrity()

Compute and record sparse-aware BLAKE3 Merkle integrity during creation. verify() checks it explicitly; ordinary open, boot, save, load, and upgrade preserve the value without adding an independent payload pass.

snapshot_builder.resumable()

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

snapshot_builder.build()

Materialize the SnapshotConfig without creating the snapshot. Errors with InvalidConfig if from_sandbox was not called. For capturing, use create instead; it calls build internally.

Returns

Validated snapshot configuration.

snapshot_builder.create()

Build and execute the snapshot in one step. Equivalent to Snapshot::create(self.build()?).

Returns

The created artifact handle.

Types

SnapshotConfig

Used by Snapshot::create() · returned by build()

Inputs to create a snapshot. A type alias for SnapshotSpec. Usually built via SnapshotBuilder rather than constructed directly.

SnapshotFormat

Used by format() · Manifest.format

On-disk format of the captured upper layer. Today only Raw is produced; the variant exists so qcow2 chains drop in later without a schema migration.

SnapshotScope

enum

Used by scope() · Manifest.scope

Snapshot payload scope. Parsing accepts every known scope so older runtimes can still list and inspect artifacts they cannot restore; create and restore paths enforce support. Re-exported as microsandbox::snapshot::SnapshotScope.

SaveOpts

struct

Used by Snapshot::save()

Options for Snapshot::save(). Implements Default; SaveOpts::default() writes the head snapshot only, zstd-compressed.

SnapshotVerifyReport

Returned by verify()

Result of explicit snapshot verification.

UpperVerifyStatus

Used by SnapshotVerifyReport.upper

Upper-layer content verification result.

Manifest

Returned by manifest()

The snapshot artifact manifest, the source of truth for an artifact, serialized as the snapshot.json descriptor (DESCRIPTOR_FILENAME). Re-exported as microsandbox::snapshot::Manifest. Its SHA-256 digest over the canonical byte form is the snapshot’s identity. Field order is load-bearing (it determines the canonical byte layout) and must not be reordered.

ImageRef

Used by Manifest.image

Reference to the OCI image the snapshot was taken from. Re-exported as microsandbox::snapshot::ImageRef.

UpperLayer

Used by Manifest.upper

Captured upper-layer file metadata. Re-exported as microsandbox::snapshot::UpperLayer.

UpperIntegrity

Used by UpperLayer.integrity

Content integrity descriptor for the captured upper layer.