Skip to main content
Capture the disk state of a stopped sandbox as a reusable artifact, then boot fresh sandboxes from it. Snapshots are disk-only and require a sandbox that is not running. See Snapshots for concepts and walkthroughs.

Typical flow

Take a snapshot

handle.snapshot()

Snapshot this sandbox under a bare name in the default snapshots directory (~/.microsandbox/snapshots/<name>/). The sandbox must be stopped or crashed. To place the artifact elsewhere, use Snapshot.save() / Snapshot.load() or move the self-contained artifact directory. Called on a SandboxHandle, obtained from Sandbox.get().

Parameters

namestr
Snapshot name; resolved under the default snapshots directory.

Returns

The captured snapshot.

Snapshot.create()

Create a snapshot from a stopped or crashed sandbox. name is resolved under the default snapshots directory (~/.microsandbox/snapshots/<name>/), or under dest_dir= when given; from_sandbox= names the sandbox to capture and is required.

Parameters

namestr
Bare snapshot name; resolved under the default snapshots directory.
from_sandboxstr
Name of the stopped or crashed sandbox to capture. Required.
dest_dirstr | os.PathLike[str] | None
Parent directory to create the artifact in; the artifact lands at dest_dir/<name>. Defaults to the snapshots directory.
labelsdict[str, str] | None
User-supplied labels stored in the manifest.
forcebool
Overwrite an existing artifact with the same name. Default False.
record_integritybool
Record an integrity hash in the manifest so the artifact can be verified later. Default False.
resumablebool
Request a “resumable” snapshot (disk plus VM state). Accepted, but currently fails with an Unsupported error; resumable snapshots have not landed yet. Default False.

Returns

The captured snapshot.

Boot from a snapshot

Sandbox.create()

Boot a fresh sandbox from a snapshot artifact by passing from_snapshot= as a peer of image=. The two are mutually exclusive: pass exactly one. See Sandbox.create() for the full set of configuration kwargs.

Parameters

namestr
Sandbox name, up to 128 UTF-8 bytes.
from_snapshotstr | os.PathLike | None
Snapshot bare name or artifact path to boot from instead of image=.

Returns

Running sandbox.

Manage artifacts

Snapshot.open()

Open an existing artifact by bare name (resolved under the default snapshots directory) or path. Cheap metadata validation only; does not read the upper file. Use verify() for content checks.

Parameters

path_or_namestr
Bare snapshot name or artifact directory path.

Returns

The opened snapshot.

Snapshot.get()

Look up a handle in the local index by name, digest, or path.

Parameters

name_or_digeststr
Snapshot name, digest, or path.

Returns

Lightweight handle backed by an index row.

Snapshot.list()

List indexed snapshots from the local DB cache.

Returns

Indexed snapshot handles.

Snapshot.list_dir()

Walk a directory and parse each subdirectory’s manifest. Does not touch the index, useful for inspecting external snapshot collections (e.g. a mounted volume of artifacts that were never loaded). Skips entries that don’t look like snapshot artifacts.

Parameters

dirstr | os.PathLike
Directory to scan for artifacts.

Returns

One snapshot per valid artifact directory.

Snapshot.remove()

Remove a snapshot artifact and its index row. Refuses if the snapshot has indexed children unless force=True.

Parameters

path_or_namestr
Bare snapshot name or artifact path.
forcebool
Remove even if the snapshot has indexed children. Default False.

Snapshot.reindex()

Walk dir (default: configured snapshots dir) and rebuild the local index. Returns the number of artifacts indexed.

Parameters

dirstr | os.PathLike | None
Directory to scan. Default: the configured snapshots directory.

Returns

int
Number of artifacts indexed.

Snapshot.save()

staticasync
Bundle a snapshot into a .tar.zst archive. The existing snapshot manifest is archived as-is; create the snapshot with recorded integrity when the archive will cross a trust boundary.

Parameters

name_or_pathstr
Snapshot bare name or artifact path to save.
outstr | os.PathLike
Output archive path.
with_parentsbool
Include the snapshot’s parent chain. Default False.
with_imagebool
Include the pinned base image. Default False.
plain_tarbool
Write an uncompressed .tar instead of .tar.zst. Default False.

Move artifacts


Snapshot.load()

staticasync
Unpack a snapshot archive (.tar.zst or .tar) into the snapshots directory, verifying recorded integrity when present. Compression is detected from magic bytes.

Parameters

archivestr | os.PathLike
Archive path (.tar.zst or .tar).
deststr | os.PathLike | None
Destination directory. Default: the configured snapshots directory.

Returns

Handle to the loaded snapshot.

Inspect

snap.verify()

Recompute the upper layer’s content hash and compare against the manifest. Walks data extents only, so a 4 GiB sparse file with a few MB of data verifies in milliseconds.

Returns

dict[str, Any]
Verification report. The upper.kind field is “not_recorded” when no integrity hash was stored, or “verified” with the recomputed digest.
The report shape:

handle.open()

Load the full Snapshot metadata for this handle. Metadata-validated only; does not read the upper file.

Returns

The opened snapshot.

handle.remove()

Remove this snapshot artifact and its index row. Refuses if the snapshot has indexed children unless force=True.

Parameters

forcebool
Remove even if the snapshot has indexed children. Default False.

Types

Snapshot

class

Returned by snapshot() · Snapshot.create() · Snapshot.open() · Snapshot.list_dir() · handle.open()

A fully-parsed snapshot artifact. Properties are read-only attributes (not async).

SnapshotHandle

class

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

Lightweight handle backed by an index row. Properties are read-only attributes (not async).