Introducing a new way to review your PRs.

Read the announcement

superradcompany / microsandbox

🧱 easy, fast, programmable and local-first microVM runtime and library

View on GitHub

27 documents · Updated Nov 23, 2026

docs / images-and-snapshots

Images, root filesystems, and snapshots

Microsandbox turns an image source into a bootable root filesystem and keeps the result reusable across sandboxes. It separates immutable image content from writable sandbox state, then lets engineers capture that state as a disk snapshot or a full checkpoint that still points to the exact image it needs.

System boundary

Image sources

An image source is the input used to form the guest root filesystem. Microsandbox treats a registry image as an OCI image reference and treats local directories or disk files as direct host resources. This distinction decides whether the system pulls and materializes content or passes an existing filesystem to the guest (sdk/…/types.rs• L14-31, sdk/…/types.rs• L691-720).

SourceRoot filesystem behavior
OCI image referenceResolve an image, cache its layers, and prepare a bootable image view.
Local directoryExpose the directory as the guest root. No image pull or layer merge occurs.
Disk image fileAttach the file as a guest block device. It follows a disk-image path rather than an OCI layer path.

References: sdk/…/types.rs• L14-31 sdk/…/types.rs• L691-720 sdk/…/types.rs• L966-1048

Root filesystem roles

An OCI root filesystem has an immutable base and a writable upper layer. The base supplies image files while the upper layer holds changes made by one sandbox. The runtime can use either a layer-aware base or one complete flat image (sdk/…/spawn.rs• L2548-2599).

RolePurpose
Immutable baseShared image content used by many sandboxes.
Writable upperSandbox-specific changes kept separate from the base.
Flat root filesystemOne complete ext4 base for workflows that do not need separate image layers.

References: sdk/…/spawn.rs• L2548-2599 crates/…/vm.rs• L317-340

Image acquisition

Registry and archive inputs

Registry acquisition resolves the requested image to a platform-specific manifest. A manifest is the image record that names its layers; the image configuration supplies the matching uncompressed layer identities and runtime defaults. Multi-platform images are narrowed to the host operating system and architecture before layer work starts (crates/…/client.rs• L576-697).

Local Docker and OCI archives enter through the same image path after their metadata and blobs are checked. This gives offline imports the same cache records and root filesystem choices as registry pulls. A warm archive import can use the existing materialized image after it checks the small metadata blobs and confirms that the advertised layer members exist (crates/…/docker.rs• L692-841, crates/…/docker.rs• L981-1117).

References: crates/…/client.rs• L576-697 crates/…/docker.rs• L692-841 crates/…/docker.rs• L981-1117

Layer acquisition

A layer is one ordered change set in an OCI image. Microsandbox downloads each layer by its content digest, checks the downloaded bytes, and can continue an interrupted download from a partial file. The system then checks the uncompressed layer identity before it accepts the layer as image content (crates/…/download.rs• L34-48, crates/…/download.rs• L70-165, crates/…/client.rs• L949-961).

The pull policy controls whether the registry can be contacted. A cached image can be used as-is, a pull can refresh the manifest while reusing matching layers, or a local-only policy can reject an incomplete cache (crates/…/pull.rs• L11-24).

References: crates/…/download.rs• L34-48 crates/…/download.rs• L70-165 crates/…/client.rs• L949-961 crates/…/pull.rs• L11-24

Cache and layer reuse

Content identities

The image cache uses different identities for different kinds of data. Compressed layer blobs and materialized per-layer files use layer content identities, while a merged image view uses the resolved manifest identity. This allows images that share layers to share stored content without confusing one image's merged filesystem with another's (crates/…/store.rs• L21-40, crates/…/store.rs• L91-119).

The cache also stores image metadata that connects a reference to its resolved manifest, configuration, and ordered layers. Snapshot restore can search this metadata by the pinned manifest digest when a tag has changed or is not present locally (crates/…/store.rs• L91-119, crates/…/client.rs• L150-173).

Image operations can keep an operation scope after resolution. The scope pins the exact metadata and artifact generation through durable catalog or sandbox publication, so pruning cannot remove a result between use and ownership transfer (crates/…/lease.rs• L14-20, crates/…/lease.rs• L57-121).

References: crates/…/store.rs• L91-119 crates/…/lease.rs• L14-20 crates/…/lease.rs• L57-121 crates/…/client.rs• L150-234

Cache validity

Cache entries are reusable only when their structure and recorded identity are valid. Pull and materialization work uses locks and temporary outputs so concurrent requests do not publish partial artifacts. A missing or invalid derived artifact causes only the needed stage to run again (crates/…/client.rs• L761-797, crates/…/client.rs• L1044-1077).

The cache is therefore a rebuildable performance layer rather than the authority for image meaning. The manifest and its layer identities define what must be rebuilt; the cache records which reusable results are already available. An EROFS cache hit is accepted only when its filesystem structure can be read, not only when its file size looks plausible (crates/…/store.rs• L148-188, crates/…/store.rs• L989-1015).

References: crates/…/client.rs• L939-975 crates/…/client.rs• L1044-1077 crates/…/store.rs• L989-1015 crates/…/lock.rs• L41-109

Root filesystem artifacts

Layered root filesystems

The layered form keeps image layers separate while presenting one read-only root to the guest. Microsandbox converts each layer into an immutable filesystem artifact, combines their metadata in layer order, and creates a small virtual-disk description that points to the required pieces (crates/…/client.rs• L733-797, crates/…/client.rs• L1098-1166).

The guest receives this read-only base beside a writable upper disk. Changes can then diverge per sandbox without copying the shared image data (sdk/…/spawn.rs• L2566-2599, crates/…/vm.rs• L1462-1525). See Image materialization formats for the detailed artifact model.

References: crates/…/client.rs• L733-797 crates/…/client.rs• L1098-1166 sdk/…/spawn.rs• L2566-2599 crates/…/vm.rs• L1462-1525

Flat root filesystems

The flat form merges the ordered image layers into one complete ext4 root filesystem. The cache stores the bytes as a content-addressed immutable blob and keeps a manifest-keyed reference that records the materializer inputs. Each sandbox creates its own private copy before it adds writable runtime state (crates/…/flat.rs• L27-88, crates/…/store.rs• L468-597, sdk/…/flat_rootfs.rs• L24-57).

Layered and flat requests share the per-layer stage. A later flat request can use cached layer artifacts without fetching the source image again, while the derivation identity prevents a different platform, layer order, or materializer ABI from reusing the wrong flat result. The selected form is part of sandbox creation so the runtime attaches the matching kind of root disk (crates/…/flat.rs• L115-165, crates/…/client.rs• L315-376, sdk/…/create.rs• L117-180).

References: crates/…/flat.rs• L27-165 crates/…/store.rs• L468-597 sdk/…/flat_rootfs.rs• L24-57 crates/…/client.rs• L315-376 sdk/…/create.rs• L117-180

Snapshot lifecycle

Snapshot creation

A snapshot is a durable capture of a sandbox's root state. Microsandbox supports a disk snapshot for an OCI-rooted managed or flat root disk and a full snapshot for a running sandbox whose runtime checkpoint includes memory and device state (sdk/…/create.rs• L249-379, sdk/…/create.rs• L443-487, sdk/…/create.rs• L867-1008).

Disk capture produces a file-state artifact made from the sandbox's physical disk layers. Full capture asks the runtime for a checkpoint closure, validates that closure, and stores it with a descriptor that records the pinned image, root layout, restore intent, and capture consistency. A full capture can preserve execution state; a disk snapshot is a cold-start source and does not contain process memory (sdk/…/create.rs• L490-576, sdk/…/create.rs• L1063-1191).

Creation stages the payload and descriptor before publication. The source sandbox is checked again before the staged artifact is committed, and lineage advances only after the artifact or archive is durable. The completed artifact is then added to its snapshot group and local index. A failed capture or publication does not expose a partial artifact (sdk/…/create.rs• L165-224, sdk/…/create.rs• L248-442, sdk/…/store.rs• L151-264).

References: sdk/…/create.rs• L122-224 sdk/…/create.rs• L248-442 sdk/…/create.rs• L444-581 sdk/…/create.rs• L584-873 sdk/…/create.rs• L875-1019 sdk/…/store.rs• L151-264

Snapshot ancestry

Snapshot ancestry records the last successfully published snapshot for a particular sandbox instance. A source lock and a small lineage cursor keep concurrent captures ordered and prevent a removed or replaced sandbox with the same name from inheriting the old chain (sdk/…/lineage.rs• L29-95, sdk/…/lineage.rs• L102-182).

The parent belongs to the immutable snapshot descriptor rather than to a group name or export choice. The cursor advances only after the artifact or archive is durable, so an unsuccessful capture does not change the next capture's parent (sdk/…/create.rs• L162-224, sdk/…/lineage.rs• L68-95).

References: sdk/…/lineage.rs• L29-95 sdk/…/lineage.rs• L102-182 sdk/…/create.rs• L162-224

Snapshot restoration

Restoration starts with the snapshot descriptor rather than a new image choice. Metadata inspection applies the recorded image, root layout, restore mode, and guest requirements before payload extraction. The descriptor pins the image reference and manifest digest, while the captured file layers or checkpoint closure provide the writable state needed to build a child sandbox (sdk/…/inspect.rs• L46-124, sdk/…/builder.rs• L1116-1258, sdk/…/archive.rs• L358-425).

File snapshots restore as ext4 disk state and can use raw or qcow2 layer payloads. Full checkpoint snapshots support either a full restore that supplies checkpoint state for resume or a disk-only restore that materializes disk state without resuming the captured execution. See Checkpoint and restore for the runtime side of this flow (sdk/…/archive.rs• L1151-1212, sdk/…/archive.rs• L1213-1277).

Each restored child receives its own writable state. It does not alter the source snapshot or another child made from the same snapshot, and image identity checks prevent applying a disk state to a different base. Selected captured additional disks are also copied into child-private files after their guest paths, sizes, integrity, and format are checked (sdk/…/delta.rs• L752-869, sdk/…/additional_disks.rs• L15-153, sdk/…/store.rs• L70-124).

References: sdk/…/inspect.rs• L46-124 sdk/…/builder.rs• L1116-1258 sdk/…/archive.rs• L358-487 sdk/…/delta.rs• L752-869 sdk/…/additional_disks.rs• L15-153 sdk/…/store.rs• L70-124

Snapshot archives

Snapshot archives transport a snapshot artifact and its boot dependencies. The default format is a zstd-compressed tar archive; plain tar is also accepted. Sparse disk files are stored by their allocated ranges, so archive work follows written data instead of the configured logical disk size (sdk/…/archive.rs• L1-10, sdk/…/archive.rs• L263-361).

An archive can include the head snapshot, its parent chain, and the cached image objects needed for offline restore. Incremental archives may omit immutable disk layers, checkpoint RAM objects, or owned payloads when an explicit base supplies them. The archive inventory states these dependencies by content identity and marks the archive as dependent (sdk/…/delta.rs• L531-649, sdk/…/delta.rs• L752-869).

Loading stages archive members, verifies descriptor and payload bindings, fills declared dependencies from supplied archives or an explicit base, and publishes only a complete result. Metadata inspection can reject an archive before payload extraction. The local index speeds lookup and listing, but the artifact and its descriptor remain the authority and can rebuild the index after a move or recovery (sdk/…/inspect.rs• L128-270, sdk/…/archive.rs• L944-979, sdk/…/archive.rs• L1034-1159, sdk/…/delta.rs• L872-972, sdk/…/store.rs• L418-468).

The archive path can also stream a new disk or full checkpoint capture directly to an archive. This avoids installing a local snapshot member while retaining the same descriptor and publication ordering (sdk/…/create.rs• L579-796, sdk/…/create.rs• L798-865). See Image materialization formats for the image cache objects that an offline bundle can carry.

References: sdk/…/archive.rs• L1-10 sdk/…/archive.rs• L263-361 sdk/…/inspect.rs• L128-270 sdk/…/archive.rs• L944-979 sdk/…/archive.rs• L1034-1277 sdk/…/delta.rs• L531-649 sdk/…/delta.rs• L752-972 sdk/…/create.rs• L579-865 sdk/…/store.rs• L418-468

Change checklist

When these files or sections are changed, remember to consider these:

  • When image manifest or config identity rules change, check registry pulls, archive imports, cache lookup by manifest digest, and snapshot restore.
  • When layer order or layer output changes, check both layered and flat root filesystem consumers.
  • When root filesystem selection changes, check the runtime's base and upper-disk pairing and snapshot eligibility.
  • When snapshot descriptor fields or state types change, check snapshot identity, restore qualification, archive contents, and index projections.
  • When snapshot capture or lineage publication changes, check source replacement handling, parent selection, group publication, and direct archive capture.
  • When archive inventory or dependency rules change, check complete archives, dependent archives, explicit base selection, payload identity checks, and offline image bundles.
  • When cache artifact names or required files change, check offline snapshot bundles and cache pruning together.
  • When operation-scoped cache ownership changes, check image import, snapshot image bundling, sandbox publication, and prune admission together.
  • When captured additional-disk bindings or restore choices change, check guest-path identity, child-private copying, and full-restore device handling together.

Important failure modes

TriggerConsequenceGuard
No image manifest matches the host platformImage acquisition stops before a root filesystem is built.Platform resolution requires a compatible operating system and architecture (crates/…/client.rs• L617-676).
A layer's compressed or uncompressed digest is wrongThe layer is rejected and cannot become a bootable image artifact.Download and materialization stages verify both identities (crates/…/download.rs• L269-281, crates/…/client.rs• L949-961).
Required cached artifacts are missing or invalidThe system rebuilds them or fails when the source data is unavailable.Cache validity checks read EROFS structure before reuse and materialization is coordinated by locks (crates/…/client.rs• L939-975, crates/…/store.rs• L989-1015).
Snapshot base image digest differs from the resolved imageRestore stops rather than applying changes to a different base.The descriptor keeps the image digest and restore validates the resolved closure (sdk/…/delta.rs• L872-972, sdk/…/store.rs• L70-124).
Snapshot source uses an unsupported root disk or capture modeSnapshot creation is refused.Disk capture admits managed or flat OCI roots, while full capture requires a running OCI root (sdk/…/create.rs• L309-379, sdk/…/create.rs• L867-894).
Snapshot archive has incomplete or mismatched bindingsImport stops before partial state becomes visible.Inventory, descriptor, dependency, and payload checks run before publication (sdk/…/archive.rs• L1130-1159, sdk/…/delta.rs• L752-972).
A dependent archive is loaded without its exact base or required payloadsRestore cannot complete the snapshot closure.Dependency records require an explicit base or supplied matching sources (sdk/…/delta.rs• L128-161, sdk/…/delta.rs• L752-823).
A source sandbox is replaced during captureThe capture is rejected rather than attached to the new sandbox instance.Lineage locks and source identity checks protect the capture sequence (sdk/…/lineage.rs• L47-65, sdk/…/lineage.rs• L119-182).
A selected captured disk has an unknown or mismatched guest pathRestore stops before it creates a child disk mount.Restore resolves all choices first and checks the device identity, format, size, and integrity (sdk/…/additional_disks.rs• L23-105, sdk/…/additional_disks.rs• L176-231).

Key files

FileWhy to read it
sdk/…/types.rsDefines the high-level image source and root-disk choices.
crates/…/client.rsShows image resolution, cache reuse, layer processing, and rootfs assembly.
crates/…/download.rsShows how layer content enters the cache and gains trust through digest checks.
crates/…/store.rsDefines the relationship between image metadata, layer artifacts, and derived rootfs artifacts.
crates/…/lease.rsShows how image operations retain cache entries through durable publication.
crates/…/storage_lease.rsDefines shared reads, publication protection, and prune-safe artifact ownership.
crates/…/lock.rsShows cross-process coordination for cache downloads and materialization.
crates/…/flat.rsExplains the complete flat rootfs path and its reuse model.
sdk/…/create.rsConnects image resolution to sandbox creation and root-disk selection.
sdk/…/spawn.rsShows how the selected immutable base and writable upper reach the VM.
sdk/…/create.rsDefines disk and full capture, artifact staging, and direct archive capture.
sdk/…/lineage.rsDefines source locks, parent selection, and ancestry publication.
sdk/…/archive.rsDefines archive contents, sparse transport, offline image support, and restore materialization.
sdk/…/inspect.rsShows how restore metadata is checked before archive payload extraction.
sdk/…/delta.rsDefines incremental archive dependencies and exact base resolution.
sdk/…/additional_disks.rsShows how selected captured disks become private child mounts.
sdk/…/store.rsValidates artifacts and maintains the rebuildable local snapshot index.
sdk/…/dispatch.rsConnects public snapshot operations to the local artifact, archive, and store flows.
crates/…/manifest.rsDefines snapshot identity, pinned image metadata, root state, and restore state types.
sdk/…/builder.rsShows how a snapshot becomes a new sandbox configuration.