Typical flow
Static methods
Snapshot::builder()
Example
Example
source_sandbox. The builder lets you set the destination, labels, and whether to record content integrity before capturing. See SnapshotBuilder for all options.
Parameters
source_sandboximpl Into<String>Returns
Snapshot::create()
Example
Example
manifest.json and the captured upper.ext4 into the destination directory atomically (the manifest 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
configSnapshotConfigReturns
Snapshot::open()
Example
Example
. 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>Returns
Snapshot::get()
Example
Example
SnapshotHandle in the local index by name, digest (sha256:/sha512: prefix), or path.
Parameters
name_or_digest&strReturns
Snapshot::list()
Example
Example
list_dir to enumerate artifacts on disk directly.
Returns
Snapshot::list_dir()
Example
Example
manifest.json) and malformed artifacts.
Parameters
dirimpl AsRef<Path>Returns
Snapshot::remove()
Example
Example
force is set. The artifact directory is deleted on success and the parent’s child count is decremented.
Parameters
path_or_name&strforcebooltrue, remove even if the snapshot has indexed children.Snapshot::reindex()
Example
Example
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>Returns
Snapshot::export()
Example
Example
.tar.zst archive (or plain .tar) at out. The head snapshot is verified before bundling. The recorded manifest is archived as-is, so create the snapshot with record_integrity() when the archive will cross a trust boundary. See ExportOpts to also include ancestors and the OCI image cache.
Parameters
name_or_path&strout&PathoptsExportOptsExportOpts::default() writes the head snapshot only, zstd-compressed.Snapshot::import()
Example
Example
.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. Recorded integrity is verified as artifacts land. Returns a handle for the head snapshot.
Parameters
archive_path&PathdestOption<&Path>None uses the default snapshots directory.Returns
Instance methods
Methods on an openedSnapshot artifact.
snap.digest()
sha256:hex). This is the snapshot’s identity.
Returns
sha256:hex form.snap.path()
manifest.json and the captured upper file.
Returns
snap.manifest()
Example
Example
Manifest: schema, format, fstype, image reference, parent, creation time, labels, and upper-layer metadata.
Returns
snap.size_bytes()
Returns
snap.verify()
Example
Example
NotRecorded when the manifest has no integrity descriptor; errors with SnapshotIntegrity on mismatch.
Returns
SnapshotHandle methods
Accessors and lifecycle on aSnapshotHandle (an index row). Returned by Snapshot::get(), Snapshot::list(), and Snapshot::import().
h.digest()
sha256:hex), the canonical identity.
h.name()
None for digest-only entries.
h.parent_digest()
None for a root. Always None today; populated once chained snapshots land.
h.image_ref()
h.format()
Returns
Raw today).h.size_bytes()
h.created_at()
h.path()
h.open()
Example
Example
Snapshot. Equivalent to Snapshot::open(self.path()).
Returns
h.remove()
Example
Example
Snapshot::remove(self.digest(), force).
Parameters
forcebooltrue, remove even if the snapshot has indexed children.Sandbox entry points
Snapshot-related methods that live on the sandbox builder and handle. See Sandbox for the full sandbox API..from_snapshot()
Example
Example
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 opened and its integrity verified at create() time, not here.
Parameters
path_or_nameimpl Into<String>h.snapshot()
Example
Example
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. For an explicit destination see snapshot_to().
Parameters
name&strReturns
h.snapshot_to()
Example
Example
SandboxHandle method. Snapshot this sandbox to an explicit filesystem path. The sandbox must be stopped or crashed. Local handles only. For the common case of writing under the default snapshots directory see snapshot().
Parameters
pathimpl AsRef<Path>Returns
SnapshotBuilder
Builder for aSnapshotConfig. Obtained via Snapshot::builder(source_sandbox). A destination is required (name or path); the other setters are optional. Every setter returns Self, so calls chain.
.destination()
name and path setters are convenience wrappers over this.
Parameters
.name()
SnapshotDestination::Name.
Parameters
nameimpl Into<String>/, or start with ...path()
SnapshotDestination::Path.
Parameters
pathimpl Into<PathBuf>.label()
Parameters
keyimpl Into<String>valueimpl Into<String>.force()
SnapshotAlreadyExists if the destination directory exists.
.record_integrity()
verify() checks and what import/export rely on when crossing a trust boundary.
.build()
SnapshotConfig without creating the snapshot. Errors with InvalidConfig if no destination was set. For capturing, use create instead; it calls build internally.
Returns
.create()
Snapshot::create(self.build()?).
Returns
Types
SnapshotHandle
Returned by Snapshot::get() · Snapshot::list() · Snapshot::import()
A lightweight handle backed by a local index row. Useopen() to read the artifact metadata, and Snapshot::verify() for explicit content verification. All accessors are listed under SnapshotHandle methods.
| Method | Type | Description |
|---|---|---|
| digest() | &str | Manifest digest (sha256:hex) |
| name() | Option<&str> | Name alias; None for digest-only entries |
| parent_digest() | Option<&str> | Parent snapshot digest, or None for a root |
| image_ref() | &str | Source image reference |
| format() | SnapshotFormat | On-disk upper format |
| size_bytes() | Option<u64> | Upper file size at index time |
| created_at() | chrono::NaiveDateTime | Creation time from the manifest |
| path() | &Path | Local artifact directory |
| open() | Result<Snapshot> | Open the underlying artifact |
| remove(force) | Result<()> | Remove this snapshot |
SnapshotConfig
Used by Snapshot::create() · returned by build()
Inputs to create a snapshot. A type alias forSnapshotSpec. Usually built via SnapshotBuilder rather than constructed directly.
| Field | Type | Description |
|---|---|---|
| source_sandbox | String | Name of the source sandbox; must be stopped |
| destination | SnapshotDestination | Where to write the artifact |
| labels | Vec<(String, String)> | User-supplied labels |
| force | bool | Overwrite an existing artifact at the destination |
| record_integrity | bool | Compute and record upper-layer integrity at creation |
SnapshotDestination
Used by destination() · SnapshotConfig.destination
Where to place a new snapshot artifact. The builder’sname() and path(), and the handle’s snapshot() / snapshot_to(), construct this enum internally so callers rarely import it.
| Variant | Fields | Description |
|---|---|---|
Name | String | Bare name resolved under the default snapshots directory |
Path | PathBuf | Explicit absolute or relative path to the artifact directory |
SnapshotFormat
Used by format() · Manifest.format
On-disk format of the captured upper layer. Today onlyRaw is produced; the variant exists so qcow2 chains drop in later without a schema migration.
| Value | Description |
|---|---|
Raw | Raw ext4 image, sparse on disk |
Qcow2 | qcow2 with optional backing chain (future) |
ExportOpts
Used by Snapshot::export()
Options forSnapshot::export(). Implements Default; ExportOpts::default() writes the head snapshot only, zstd-compressed.
| Field | Type | Description |
|---|---|---|
| with_parents | bool | Walk the parent chain and include each ancestor in the archive |
| with_image | bool | Bundle the OCI image artifacts (EROFS layers, fsmeta, VMDK descriptor) from the global cache so the archive boots offline |
| plain_tar | bool | Skip zstd compression and write a plain .tar. Default: zstd |
SnapshotVerifyReport
Returned by verify()
Result of explicit snapshot verification.| Field | Type | Description |
|---|---|---|
| digest | String | Snapshot manifest digest |
| path | PathBuf | Artifact directory |
| upper | UpperVerifyStatus | Upper-layer content verification result |
UpperVerifyStatus
Used by SnapshotVerifyReport.upper
Upper-layer content verification result.| Variant | Fields | Description |
|---|---|---|
NotRecorded | - | No content integrity descriptor was recorded in the manifest |
Verified | - algorithm: String - digest: String | Recorded integrity matched the computed digest |
Manifest
Returned by manifest()
The snapshot artifact manifest, the source of truth for an artifact. Re-exported asmicrosandbox::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.
| Field | Type | Description |
|---|---|---|
| schema | u32 | Manifest schema version; readers reject unknown values |
| format | SnapshotFormat | On-disk format of the upper layer |
| fstype | String | Filesystem type inside the upper (e.g. ext4) |
| image | ImageRef | Image the snapshot was taken from |
| parent | Option<String> | Parent snapshot digest, or None for a root |
| created_at | String | RFC 3339 creation timestamp |
| labels | BTreeMap<String, String> | User-supplied labels, sorted by key in canonical form |
| upper | UpperLayer | The captured upper layer |
| source_sandbox | Option<String> | Best-effort name of the source sandbox (informational) |
ImageRef
Used by Manifest.image
Reference to the OCI image the snapshot was taken from. Re-exported asmicrosandbox::snapshot::ImageRef.
| Field | Type | Description |
|---|---|---|
| reference | String | Human-readable image reference (e.g. docker.io/library/python:3.12) |
| manifest_digest | String | Digest of the OCI manifest, in sha256:hex form |
UpperLayer
Used by Manifest.upper
Captured upper-layer file metadata. Re-exported asmicrosandbox::snapshot::UpperLayer.
| Field | Type | Description |
|---|---|---|
| file | String | Filename inside the artifact directory (e.g. upper.ext4) |
| size_bytes | u64 | Apparent size in bytes (ext4 virtual size; sparse on disk) |
| integrity | Option<UpperIntegrity> | Optional content integrity descriptor; None on local hot paths |
UpperIntegrity
Used by UpperLayer.integrity
Content integrity descriptor for the captured upper layer.| Field | Type | Description |
|---|---|---|
| algorithm | String | Digest algorithm name (e.g. msb-sparse-sha256-v1) |
| digest | String | Algorithm output, in sha256:hex form for current algorithms |