Skip to main content
See the snapshot guide for workflows and examples. Use snapshot objects or references on cloud. Local operations also accept a group head, group:member, or artifact path.

Guest writeback

Use .guest_flush(GuestFlush::Required) on snapshot, fork, or fork-many builders, or source.pause_with_guest_flush(GuestFlush::Required). Import GuestFlush from microsandbox::snapshot. The default Auto flushes live disk-only captures, but adds no optional flush to full captures, forks, or pause. Skip retains mandatory storage barriers. A paused disk capture needs a matching prior flush; cloud rejects non-Auto policies. See guest flush policy reference.

Static methods

Snapshot::builder()

Configure a snapshot. Set the required source with from_sandbox(); see SnapshotBuilder for options.

Parameters

nameimpl Into<String>
Member name; generated when empty. Names must not contain path separators or start with ..

Returns

Builder for configuring the snapshot.

Snapshot::create()

Create an installed snapshot artifact atomically, then best-effort update the rebuildable local index. Locally, disk mode supports running, paused, stopped, and crashed sources; full mode includes memory and execution state from a running or paused source. Cloud supports only disk capture from a stopped persistent source. 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::create_archive()

Capture a disk or full snapshot directly into an archive without installing it locally.

Snapshot::open()

Open an existing artifact by group head, group:member, or 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. For the local backend, relative artifact paths are resolved when the operation begins, and the returned snapshot retains that absolute location. Changing the process working directory later does not retarget an opened or listed snapshot. Local import, export, copy, and capture destinations are also resolved before asynchronous work starts. Group names and snapshot IDs continue to resolve through the snapshot store.

Parameters

path_or_nameimpl AsRef<str>
Group head, group:member, 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 by group head, group:member, stable snapshot ID, descriptor digest, or artifact path. Global IDs and digests must resolve unambiguously.

Parameters

name_or_digest&str
Group head, group:member, stable snapshot ID, descriptor digest, or artifact path.

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 group selector, unambiguous ID or digest, or path, along with its index row. Refuses if the snapshot has indexed children unless force is set. A group’s head cannot be removed while other members remain, even with force; select another head first.

Parameters

path_or_name&str
Group head, group:member, unambiguous snapshot ID or digest, 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 snapshot index from artifacts in dir.

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 .msb 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
Group head, group:member, 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 (.msb 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 archive-declared head snapshot, which may differ from the receiving group’s selected head.

Instance methods

Methods on an opened Snapshot artifact.

Snapshot::load_with_base()

Import an archive with an explicit dependency base or destination group. See import options.

Snapshot::load_with_options()

Import an archive with an explicit dependency base or destination group. See import options.

Snapshot::load_many()

Import archives as one batch. Returns handles in input order. Dependencies resolve from the batch, the named group, or an explicit base; input order does not matter. All members are validated before publication.

Snapshot::group_head()

Read a group’s head, or select an exact member with group:member. Returns the group, previous and current snapshot IDs, reason, and whether the head changed. See group selection.

Import options

Options for LoadOpts. With divergent tips, the existing head stays selected; a new group has no head. Select a member explicitly. Identical members may be reused; conflicting identities fail. See archive imports.

Instance methods

snap.id()

Stable opaque snap_... identity. Copying, archiving, or relabeling the snapshot preserves this value.

snap.digest()

SHA-256 digest of the canonical descriptor bytes. This detects descriptor conflicts but is separate from the stable snapshot ID.

Returns

&str
Manifest digest in sha256:hex form.

snap.reference()

Backend-neutral locator that preserves whether the snapshot is addressed by an identifier or path. Use it with dedicated restore and lifecycle methods without assuming client-host filesystem access.

Returns

SnapshotReference
Typed backend-relative snapshot reference.

snap.manifest()

The parsed Manifest: stable identity, state closure, capture provenance, pinned image, parent identity, and extensions. Mutable labels are exposed by labels() and are not part of this descriptor.

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

Create a new archive from this snapshot’s disk data while replacing its labels and integrity metadata. The source snapshot is unchanged. Artifact copies are currently local-only; other backends return MicrosandboxError::Unsupported when save() is awaited.

snap.verify()

Verify the snapshot’s complete state closure. File state recomputes recorded upper-layer integrity and returns NotRecorded without reading the payload when integrity is absent. Checkpoint state validates the root, manifests, disk layers, device/execution objects, and every referenced memory object, then returns the verified checkpoint root.

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

Descriptor digest (sha256:hex), separate from the stable snapshot ID.

h.name()

Member name within its group, or None when no alias is recorded.

h.parent_digest()

The captured parent snapshot’s stable ID, or None when no parent is known. The accessor retains its existing parent_digest name.

h.scope()

instance
Snapshot payload scope: SnapshotScope::Disk for a disk-only snapshot or Full for disk plus VM execution state.

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 installed snapshot copy by its stored artifact path. Other groups containing the same snapshot ID or digest remain unchanged.

Parameters

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

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 OCI-rooted source sandbox. Local disk capture also supports running and paused sources. Cloud requires a stopped persistent source.

.group()

Set the local snapshot group. Defaults to the source sandbox’s name. Direct archive capture does not accept a group.

.dest_dir()

builder
Create the snapshot group under this parent directory instead of the default snapshots store. Member names are local aliases within the group; stable snapshot IDs identify immutable artifacts.

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 direct archive output file. Installed group members are immutable, so installed creation rejects this option.

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

builder
Local-only: capture disk, memory, and execution state. The source must be running or paused and returns to that state after capture.

.guest_flush()

Select guest writeback before capture. Defaults to GuestFlush::Auto; see guest writeback.

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

SnapshotCopyBuilder

Returned by Snapshot::copy_to(). It reuses the source disk data while replacing explicit-snapshot metadata in a new archive.

RestoreBuilder

Restore into a new detached sandbox. Disk boots fresh; full resumes execution. See restore examples and progress.
Image, replacement, and startup-command options are not accepted. Full restore requires matching CPU and memory settings, keeps captured network devices, and cannot apply a new guest security profile. Use disk-only restore to change these. Full restore rejects missing external filesystems and additional disks by default. Use allow_missing_resources() to resume with unavailable devices and warnings. This is separate from strict/relaxed validation of supplied mappings; inheritance does not waive missing backing. Root and owned storage remain required.
Omitted controls retain destination defaults. Durations are whole seconds. Network policy accepts NetworkPolicy. Use |v| v.captured() for a private captured volume.

Sandbox::restore_ref()

Restore from an explicit backend-neutral snapshot reference. Pass a Snapshot or SnapshotHandle reference without reinterpreting an identifier as a path. This uses the same dedicated restore options and backend capability checks as Sandbox::restore().

h.snapshot()

SandboxHandle method. Snapshot this sandbox’s disk into its default group with the given member name. Use the returned artifact path or sandbox:member to open it later. Live captures are crash-consistent and preserve the source’s running/paused state. Local handles only. To place the artifact elsewhere, use Snapshot::save() / Snapshot::load() or move the self-contained artifact directory.

Parameters

name&str
Member name within the source sandbox’s group.

Returns

The created artifact handle.

Compaction

Compact a local sandbox’s root or owned disks. See compaction for examples and recovery requirements.
Defaults to the root and owned data disks; excludes named/external volumes and directories. Requires a running or fully stopped local sandbox. Fewer than two sealed layers means no change; no eligible disks returns an empty result with zero counts.Results include aggregate counts and per-disk entries keyed by guest_path. materialized_bytes counts copied bytes, not reclaimed space. Times are microseconds: per-disk total_us covers preparation; aggregate total_us also includes switching; pause_us measures the shared VM pause.

Types

SnapshotReference

enum
A backend-neutral snapshot locator. Obtain one from Snapshot::reference() or SnapshotHandle::reference() and pass it to Sandbox::restore_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 descriptor, serialized as snapshot.json (DESCRIPTOR_FILENAME) and re-exported as microsandbox::snapshot::Manifest. Its SHA-256 digest is computed over RFC 8785 canonical JSON. Stable lineage identity is the separate snapshot_id field.

ImageRef

Used by Manifest.image

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

DiskLayer

Used by Manifest.upper

One member of the complete oldest-first file-layer closure. Re-exported as microsandbox::snapshot::DiskLayer; UpperLayer remains a source-compatibility alias.

UpperIntegrity

Used by DiskLayer.payload.integrity

Content integrity descriptor for the captured upper layer.