Skip to main content
Capture a stopped sandbox’s writable upper layer, then list it or boot a fresh sandbox from it through the active backend. Local snapshots are self-describing, content-addressed artifacts on disk; cloud snapshots use managed storage or the organization’s host volume. See Snapshots for concepts and walkthroughs; this page is the Rust SDK reference.
Snapshots are disk-only today and capture a sandbox that is stopped or crashed. list_dir, reindex, save/save_to, load, and verify remain on the shared Snapshot API, but currently return MicrosandboxError::Unsupported with the cloud backend.

Static methods

Snapshot::builder()

Start configuring a new snapshot named name. Locally, the default destination is ~/.microsandbox/snapshots/<name>/; in cloud, the default is managed object storage. dest_dir() selects a local parent directory or a path on the organization’s host volume. The source sandbox is set with from_sandbox(), which is required.

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 from a stopped sandbox through the active backend. Locally, this atomically writes the artifact and updates the rebuildable local index. In cloud, it starts a snapshot operation and waits for the managed or host-volume snapshot to become available. Most callers use the builder’s create().

Parameters

Name, source sandbox, labels, and integrity flag.

Returns

The created artifact handle.

Snapshot::open()

Open an existing snapshot by a backend-relative string. Locally, bare names resolve under the default snapshot directory and other values are artifact paths. In cloud, bare values identify managed snapshots and path-like values identify host-volume artifacts. Prefer open_ref() when a typed SnapshotReference is already available.

Parameters

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

Returns

The opened artifact handle.

Snapshot::open_ref()

Open a snapshot from an explicit SnapshotReference. Use this when passing through a reference returned by another SDK operation; it preserves whether the backend should resolve the value as an identifier or a path.

Snapshot::get()

Look up a lightweight SnapshotHandle using the active backend: the local index locally, or the managed snapshot API in cloud.

Parameters

name_or_digest&str
Public identifier understood by the active backend (for example a local name/digest or cloud snapshot ID).

Returns

Handle backed by the matching index row.

Snapshot::list()

List snapshots from the active backend. Locally this uses the local index; in cloud it paginates through managed snapshots. Host-volume artifacts are not included automatically.

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::remove_ref()

Remove a snapshot using an explicit backend-neutral reference. Prefer this over remove() when the value came from Snapshot::reference() or SnapshotHandle::reference().

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::reindex_default()

Rebuild the local snapshot index from the configured default snapshot directory. This is equivalent to reindex() with the local backend’s configured store and returns MicrosandboxError::Unsupported on backends without a rebuildable artifact index.

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

Return the stable, backend-neutral reference accepted by SandboxBuilder::from_snapshot_ref(), Snapshot::open_ref(), and Snapshot::remove_ref(). It contains either an identifier or a path in the selected backend’s namespace; callers can pass it through without inspecting which storage implementation produced it.

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

Backend-reported stored payload size. This is the apparent upper-file size for local and host-volume artifacts, and the stored archive size for managed cloud snapshots.

Returns

u64
Upper-layer apparent size in bytes.

snap.path()

Return the local artifact directory. Cloud snapshots return MicrosandboxError::Unsupported because managed and host-volume artifacts are not paths on the client host. Use reference() for backend-neutral restore and lifecycle operations.

snap.save_to()

Bundle this snapshot into an archive using the backend retained when it was created or opened. This avoids re-resolving its reference through the current default backend. Artifact archives are currently local-only; other backends return MicrosandboxError::Unsupported.

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. The cloud backend currently returns MicrosandboxError::Unsupported.

Returns

Digest, path, and upper-layer verification status.

SnapshotHandle methods

Accessors and lifecycle on a SnapshotHandle returned by the active backend. Returned by Snapshot::get(), Snapshot::list(), and Snapshot::load().

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

Backend-reported stored payload size, if known.

h.path()

Return the local artifact directory. Cloud snapshots return MicrosandboxError::Unsupported. Use reference() for backend-neutral restore and lifecycle operations.

h.created_at()

Snapshot creation time, parsed from the manifest.

h.open()

Open the underlying snapshot metadata using the backend retained by the handle, without requiring the caller to interpret its storage location.

Returns

The opened artifact.

h.remove()

Remove this snapshot through the backend retained by the handle, preserving its identifier-versus-path reference kind.

Parameters

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

h.save_to()

Bundle the referenced snapshot into an archive through the backend retained by this handle. Artifact archives are currently local-only; other backends return MicrosandboxError::Unsupported.

Sandbox entry points

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

.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>
Backend-relative snapshot name, ID, or path.

.from_snapshot_ref()

Boot from an explicit backend-neutral snapshot reference. This is the safest way to pass a Snapshot or SnapshotHandle reference into a new sandbox without reinterpreting an identifier as a path.

h.snapshot()

SandboxHandle method. Snapshot this sandbox under a bare name using the handle’s backend. Local uses its default snapshot directory; cloud uses managed storage. The sandbox must be stopped or crashed; running sandboxes are rejected with SnapshotSandboxRunning.

Parameters

name&str
Bare snapshot name.

Returns

The created artifact handle.

h.snapshot_to()


SnapshotBuilder

Builder for a SnapshotConfig. Obtained via Snapshot::builder(name). A source sandbox is required (from_sandbox); the other setters are optional. Every setter returns Self, so calls chain.

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

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

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

.force()

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

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

.resumable()

builder
Request a future resumable snapshot (disk plus VM state). create() currently fails with Unsupported; resumable capture has not landed yet.

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

.create()

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

Returns

The created artifact handle.

Types

SnapshotReference

enum
A backend-neutral snapshot locator. Obtain one from Snapshot::reference() or SnapshotHandle::reference() and pass it to SandboxBuilder::from_snapshot_ref(), Snapshot::open_ref(), or Snapshot::remove_ref(). This preserves whether a value is an identifier or a path without exposing the selected backend. Use SnapshotReference::auto(), id(), or path() to construct a reference. value() returns the underlying string and kind() returns auto, id, or path.

SnapshotHandle

struct

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

A lightweight handle returned by the active backend. Use open() to read the snapshot metadata. The handle retains its backend, so open() and remove() work without the caller interpreting its storage location.

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() and instance save_to() methods

Options for Snapshot::save() and instance save_to() methods. 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.