Typical flow
Take a snapshot
handle.snapshot()
Example
Example
~/.microsandbox/snapshots/<name>/). The sandbox must be stopped or crashed. For an explicit filesystem destination, see snapshot_to(). Called on a SandboxHandle, obtained from Sandbox.get().
Parameters
namestrSnapshot name; resolved under the default snapshots directory.
Returns
The captured snapshot.
handle.snapshot_to()
Example
Example
Parameters
pathstr | os.PathLikeDestination artifact directory.
Returns
The captured snapshot.
Snapshot.create()
Example
Example
name= (resolved under the default snapshots directory) or path= (explicit filesystem destination) is required.
Parameters
source_sandboxstrName of the stopped or crashed sandbox to capture.
namestr | NoneSnapshot name under the default snapshots directory. Mutually exclusive with
path.pathstr | os.PathLike | NoneExplicit destination directory. Mutually exclusive with
name.labelsdict[str, str] | NoneUser-supplied labels stored in the manifest.
forceboolOverwrite an existing destination. Default
False.record_integrityboolRecord an integrity hash in the manifest so the artifact can be verified later. Default
False.Returns
The captured snapshot.
Boot from a snapshot
Sandbox.create()
Example
Example
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
namestrSandbox name, up to 128 UTF-8 bytes.
snapshotstr | os.PathLike | NoneSnapshot bare name or artifact path to boot from instead of
image=.Returns
Running sandbox.
Manage artifacts
Snapshot.open()
Example
Example
verify() for content checks.
Parameters
path_or_namestrBare snapshot name or artifact directory path.
Returns
The opened snapshot.
Snapshot.get()
Example
Example
Parameters
name_or_digeststrSnapshot name, digest, or path.
Returns
Lightweight handle backed by an index row.
Snapshot.list()
Example
Example
Returns
Indexed snapshot handles.
Snapshot.list_dir()
Example
Example
Parameters
dirstr | os.PathLikeDirectory to scan for artifacts.
Returns
One snapshot per valid artifact directory.
Snapshot.remove()
Example
Example
force=True.
Parameters
path_or_namestrBare snapshot name or artifact path.
forceboolRemove even if the snapshot has indexed children. Default
False.Snapshot.reindex()
Example
Example
dir (default: configured snapshots dir) and rebuild the local index. Returns the number of artifacts indexed.
Parameters
dirstr | os.PathLike | NoneDirectory to scan. Default: the configured snapshots directory.
Returns
int
Number of artifacts indexed.
Snapshot.export()
Example
Example
.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_pathstrSnapshot bare name or artifact path to export.
outstr | os.PathLikeOutput archive path.
with_parentsboolInclude the snapshot’s parent chain. Default
False.with_imageboolInclude the pinned base image. Default
False.plain_tarboolWrite an uncompressed
.tar instead of .tar.zst. Default False.Move artifacts
Snapshot.import_()
Example
Example
.tar.zst or .tar) into the snapshots directory, verifying recorded integrity when present. Compression is detected from magic bytes. The trailing underscore is intentional: import is a reserved Python keyword.
Parameters
archivestr | os.PathLikeArchive path (
.tar.zst or .tar).deststr | os.PathLike | NoneDestination directory. Default: the configured snapshots directory.
Returns
Handle to the imported snapshot.
Inspect
snap.verify()
Example
Example
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.handle.open()
Example
Example
Snapshot metadata for this handle. Metadata-validated only; does not read the upper file.
Returns
The opened snapshot.
handle.remove()
Example
Example
force=True.
Parameters
forceboolRemove even if the snapshot has indexed children. Default
False.Types
Snapshot
Returned by snapshot() · snapshot_to() · Snapshot.create() · Snapshot.open() · Snapshot.list_dir() · handle.open()
A fully-parsed snapshot artifact. Properties are read-only attributes (not async).| Property / Method | Type | Description |
|---|---|---|
path | str | Path to the artifact directory |
digest | str | Canonical content digest (sha256:hex). The snapshot’s identity |
size_bytes | int | Apparent size of the captured upper layer in bytes (sparse on disk) |
image_ref | str | Image reference the snapshot was taken from |
image_manifest_digest | str | OCI manifest digest of the pinned image |
format | str | "raw" or "qcow2" (always "raw" today) |
fstype | str | Filesystem type inside the upper (e.g. "ext4") |
parent | str | None | Parent snapshot’s digest, or None for a root |
created_at | str | RFC 3339 timestamp |
labels | dict[str, str] | User-supplied labels |
source_sandbox | str | None | Best-effort source-sandbox name |
verify() | Awaitable[dict[str, Any]] | Recompute and check the upper-layer integrity hash. See verify() |
SnapshotHandle
Returned by Snapshot.get() · Snapshot.list() · Snapshot.import_()
Lightweight handle backed by an index row. Properties are read-only attributes (not async).| Property / Method | Type | Description |
|---|---|---|
digest | str | Manifest digest, canonical identity |
name | str | None | Convenience alias |
parent_digest | str | None | Parent snapshot digest, or None for a root |
image_ref | str | Image the snapshot was taken from |
format | str | "raw" or "qcow2" |
size_bytes | int | None | Apparent upper size at index time |
created_at | float | ms since Unix epoch |
path | str | Local artifact directory path |
open() | Awaitable[Snapshot] | Load full metadata. See open() |
remove(force=False) | Awaitable[None] | Delete the artifact and its index row. See remove() |