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 / checkpoint-and-restore

Checkpoint and restore orchestration

Checkpoint and restore orchestration preserves a sandbox at a safe execution boundary and rebuilds it in a new runtime. It joins guest quiescence, VM state, disk and memory state, host resource admission, artifact publication, archive transport, and restore activation; Images and snapshots gives the wider snapshot model, while Image materialization formats describes related artifact behavior.

Checkpoint boundary

Execution boundary

The checkpoint coordinator creates one shared boundary for guest work, VM execution, device state, memory, and storage. It admits the active resources, parks host input, freezes the guest workload, pauses the VM, captures state from that pause generation, and resumes the source only after the checkpoint is durable.

The guest freeze records transport positions and confirms requested filesystem writeback. The coordinator waits for guest output to reach the same boundary. This prevents a restored workload from seeing a half-finished request.

The main capture results are:

  • A full checkpoint can resume application execution in a new VM.
  • A disk-only checkpoint preserves storage state without claiming to preserve RAM or the current instruction position.
  • A local branch transfers a host-local memory backing to a child without making a portable restore promise.

This diagram shows how the runtime moves from live work to a published checkpoint and then returns the source to service.

flowchart LR
    A[Running sandbox] --> B[Admit resources]
    B --> C[Park host input]
    C --> D[Freeze workload and flush required mounts]
    D --> E[Pause VM at one generation]
    E --> F[Capture devices disks execution and memory]
    F --> G[Publish checkpoint closure]
    G --> H[Resume source VM]
    H --> I[Thaw workload and release input]

References: crates/…/coordinator.rs• L812-1075 crates/…/coordinator.rs• L1252-1444

Resident pause

A resident pause is an executor-owned VM pause that does not promise a checkpoint. It can hold a prepared workload freeze for control operations, then correct the guest clock before it releases the workload or host input.

If the guest freezer is unavailable and no writeback is required, the runtime can hold host input instead. If freeze or resume recovery fails, it keeps the VM fenced rather than allowing uncertain state to run.

References: crates/…/coordinator.rs• L184-289 crates/…/coordinator.rs• L2072-2081

Pause ownership

The runtime keeps the source paused when it cannot prove that capture or recovery is safe. A failure before the durable boundary can remove staging and return the source to normal work. A failure after a disk journal or checkpoint is published keeps the VM fenced so a later start follows the durable record.

This rule separates recoverable preparation errors from errors that may have changed storage or published a checkpoint.

References: crates/…/coordinator.rs• L1027-1097 crates/…/disk.rs• L595-606

State capture

Disk generations

Runtime-owned disks capture by sealing the current writable head and creating a fresh head for continued source execution. The checkpoint receives the sealed disk closure and block-device state from the same pause generation. The source then writes only to the new head, so the captured generation stays stable.

The root disk and sandbox-owned named disks use the same generation idea. Their journals remain the authority for the active chain. Pending root growth is recorded before the filesystem change completes and must finish before a checkpoint or cold boot can use that chain.

References: crates/…/disk.rs• L476-606 crates/…/disk.rs• L684-724 crates/…/coordinator.rs• L1491-1568

Disk compaction

Disk compaction shortens a chain of sealed generations without changing the guest-visible disk. The runtime prepares a replacement prefix, validates the result, and changes the journal only when the replacement is ready.

Live compaction adopts prepared backends during a short VM pause. Stopped compaction uses the same chain and journal checks without a VM pause. Old layers remain available until journal update and backend adoption succeed, so a partial result can recover from durable per-disk state.

References: crates/…/disk.rs• L289-400 crates/…/disk.rs• L403-473 crates/…/disk.rs• L639-681

Execution state

Full capture serializes VM execution state at the same pause generation as devices and memory. Restore rejects state from another generation. Execution requirements, such as nested virtualization, become part of restore policy rather than a setting that a child can silently change.

References: crates/…/coordinator.rs• L1652-1680 crates/…/restore.rs• L225-237 crates/…/execution.rs• L15-43

Memory generations

Portable memory capture represents RAM as a manifest of zero ranges and immutable content-addressed objects. A later capture can retain a valid baseline and record only changed ranges. If the baseline generation or memory topology does not match, the coordinator uses a complete capture instead.

The capture path bounds in-flight data and overlays changed ranges onto the prior manifest. Restore reads each required object, checks its identity, and writes the described ranges into guest memory.

References: crates/…/coordinator.rs• L1808-1899 crates/…/coordinator.rs• L2026-2061 crates/…/restore.rs• L368-472

Local memory handoff

Local branching uses a complete host-local RAM backing instead of a portable RAM object closure. The source prepares the backing before the pause when possible, then transfers the backing with execution state, device state, disks, resource bindings, and boot geometry.

The child accepts an incremental local capture only when its generation and topology still match. Otherwise it takes a complete local capture. The handoff is a local execution transfer, not a portable crash-recovery artifact.

References: crates/…/coordinator.rs• L738-810 crates/…/coordinator.rs• L1683-1805 crates/…/restore.rs• L118-205

Memory backing cache

The memory backing cache materializes a complete portable memory manifest into a local read-only backing file. It can reuse a warm backing or a retained baseline, but it never changes the checkpoint identity.

Cache publication occurs only after the backing is complete and synced. Cache cleanup distinguishes active, pending-handoff, young, changed, and reclaimable files. It rechecks ownership before removal and reports logical bytes removed rather than claiming exact physical space reclaimed.

References: crates/…/coordinator.rs• L1099-1143 crates/…/cache_storage.rs• L93-184 crates/…/cache_storage.rs• L279-403

Artifact closure

Immutable checkpoint closure

The image checkpoint model stores guest-visible state as a self-contained closure. A canonical checkpoint manifest names execution state, memory state, device state, disk generations, owned volumes, and resource bindings. Immutable payloads use content identity, so repeated data can be reused without changing what the manifest means.

Restore opens the root and checks every named manifest, object, disk layer, memory range, architecture, and pause generation. Later payload reads check identity again. A valid root descriptor alone is not enough to admit a restore.

References: crates/…/mod.rs• L1-40 crates/…/resolver.rs• L31-44 crates/…/resolver.rs• L121-287

Artifact publication

Capture builds a complete artifact in private staging before it changes the installed snapshot group or exposes an archive. Installed full snapshots copy and validate the checkpoint closure before they promote the snapshot directory. Direct archives stream the same validated closure without creating an installed snapshot or index row.

The source lineage commits only after the destination artifact is durable. If source recovery fails after publication, the result identifies the published artifact separately from the source's unsafe resume. This lets callers retain a valid checkpoint without treating source recovery as successful.

References: sdk/…/create.rs• L300-368 sdk/…/create.rs• L693-796 sdk/…/create.rs• L1038-1107 sdk/…/archive.rs• L1170-1272

Launch staging

Archive and restore preparation use private launch staging before a sandbox or snapshot catalog entry exists. An owner lock ties the operation directory to its live process. A later preparation removes abandoned, unlocked operation directories but preserves active preparations.

This separates untrusted or incomplete input preparation from a published sandbox. It also gives cleanup a safe point after an interrupted launch.

References: crates/…/launch_staging.rs• L15-76 crates/…/launch_staging.rs• L83-104

Incremental archive dependencies

An incremental snapshot archive contains the target descriptor and names the exact disk layers, memory objects, and owned-volume data that its known base must provide. Import accepts a base only when its physical content matches the recorded dependency.

The dependency is an explicit input. Parent names or unrelated files in the destination cannot silently fill a missing payload.

References: sdk/…/delta.rs• L72-161 sdk/…/delta.rs• L752-972

Archive transport

Snapshot archives use a closed inventory for descriptors, checkpoint members, disk layers, and optional image data. The writer hashes each member as it is consumed, writes the inventory last, and the loader checks member names, identities, and integrity before it materializes a restore.

Sparse disk files preserve holes during transport. Archive cost therefore follows allocated data rather than logical disk capacity. The completed archive is synced in a temporary path and then replaced atomically, so an interrupted write does not look like a complete archive.

References: sdk/…/archive.rs• L1-10 sdk/…/archive.rs• L1402-1425 sdk/…/archive.rs• L1688-1851 sdk/…/archive.rs• L1019-1035

Private payload copies

Snapshot payload copies preserve source provenance while preventing a shared source from becoming a mutable child artifact. Copying uses private staging and exposes the destination only after its contents and permissions are ready.

The copy path supports disk snapshot archives. Checkpoint-state snapshots use the full export path instead of being treated as ordinary file copies. This keeps the archive kind aligned with the state the descriptor claims to contain.

References: sdk/…/copy.rs• L32-78 sdk/…/copy.rs• L128-173

Capture publication

Local snapshot creation separates capture from publication. It first builds and validates the complete artifact, then promotes it and advances source ancestry. A source lock prevents replacement during capture, and the lineage cursor advances only after the artifact is durable.

Group publication exchanges a complete generation rather than exposing a batch prefix. A crash before the exchange leaves the old generation visible. A crash after the exchange leaves the new generation recoverable, and later cleanup can retire the old generation without changing the published members.

References: sdk/…/create.rs• L218-368 sdk/…/create.rs• L423-639 sdk/…/generation_tests.rs• L736-797 sdk/…/generation_tests.rs• L820-957

Storage authority

Protected sandbox layout

The protected sandbox layout defines which host state is trusted during checkpoint, import, and restore. Existing sandboxes are admitted under lifecycle and storage protection. New restore reservations are marked before materialization can write disk chains.

Activation requires a complete ready marker, real host-owned directories, the expected guest-state boundary, and the legacy-reader guard. Guest-created links and stale files cannot select host disk authority during a later boot.

References: crates/…/layout.rs• L97-210 crates/…/layout.rs• L213-223 crates/…/layout.rs• L406-447

Legacy storage migration

Legacy migration converts host-authorized disk views into the protected journals used by current checkpoint and restore flows. Inspection is read-only. Execution pins the selected sources, records intent, captures private copies when needed, validates the complete group, and publishes protected journals through forward-only steps.

The migration path rejects links, ambiguous aliases, changing sources, unexplained files, unsupported disk chains, and input beyond shared bounds. If a crash interrupts the process, the durable record resumes the same selection or requires recovery; it does not guess a new active chain.

References: crates/…/mod.rs• L1-24 crates/…/io.rs• L45-185 crates/…/io.rs• L420-487 crates/…/namespace.rs• L27-70

Storage namespace

Migration and launch preparation validate both the requested path and its actual directory ancestry. The checks protect publication parents, reject unsafe links, and retain guards while an operation reads or publishes state.

This makes host configuration the authority for legacy roots and recovery caches. Guest metadata and archive paths can describe state, but they cannot grant permission to open an arbitrary host path.

References: crates/…/namespace.rs• L128-215 crates/…/namespace.rs• L79-125 crates/…/layout.rs• L449-546

Resource admission

Capture admission

Before the runtime freezes the workload, it checks that every active device has a safe capture treatment and that the VM can support full activation. Block devices need immutable generation providers. Filesystem devices need handle-state providers. Network devices need an effective guest binding.

Resources have one of three high-level treatments:

  • Serialize for state that must be restored from the checkpoint.
  • Reconnect for a host service that is rebuilt and attached to the restored guest.
  • Reset for state that can start fresh.

Full checkpoints also require a ready guest VM Generation ID driver, clock-aware activation support, and backend execution-state capture. Admission rejects an incomplete resource set before capture can publish a misleading artifact.

References: crates/…/coordinator.rs• L826-872 crates/…/coordinator.rs• L2305-2397

Restore admission

Restore admission opens and validates the complete closure before VM construction. It checks architecture, geometry, execution epoch, device bindings, filesystem state limits, memory ranges, disk layers, and the guest-agent contract.

Full restore starts without inherited host mounts, listeners, or user settings. Captured resources must be mapped or explicitly allowed to be missing. Disk-only restore can use destination boot settings, while full restore keeps the captured execution context and rejects incompatible overrides.

References: crates/…/restore.rs• L208-277 crates/…/restore.rs• L285-360 sdk/…/restore_builder.rs• L42-61 sdk/…/restore_builder.rs• L79-107

Writeback admission

Buffered disk writeback uses a host-wide pressure pool when policy enables it. Each eligible runtime receives a fair target and synchronizes its backing files before it releases its lease.

This controls host writeback pressure. It does not decide whether a captured resource is restorable; capture admission owns that contract.

References: crates/…/admission.rs• L66-113 crates/…/admission.rs• L145-383

External state

External mounts

External bind mounts are not copied into a portable checkpoint. The descriptor keeps their logical guest paths and host-controlled authorization. A disk-only archive restore returns the paths that the destination must provide, while a full child restore starts without inherited external mounts.

If a mount is unavailable or retained handles are stale, restore records a host-side warning outside the guest-writable runtime share. The condition remains visible after activation and is not mistaken for valid restored data.

References: sdk/…/create.rs• L589-610 sdk/…/archive.rs• L458-500 sdk/…/restore.rs• L128-167 crates/…/restore.rs• L480-513

Owned volumes

Sandbox-owned volumes are part of the checkpoint closure and are rebuilt as child-owned storage. Restore checks the canonical guest path and the captured file or disk inventory before it publishes the mount and its runtime journal.

An explicit destination mapping cannot replace captured owned data. Disk volumes retain their sealed chain and receive a private writable head. Directory volumes are materialized from their checked descriptor and payload set, so the child remains usable if the source artifact is later removed.

References: sdk/…/owned.rs• L19-133 sdk/…/owned.rs• L135-234 sdk/…/restore.rs• L334-359

Network identity

Network sockets and host allocation slots are rebuilt for the destination. The guest-visible virtual gateway identity is preserved because captured guest neighbor state can still refer to it. A full restore requires one valid captured gateway identity when networking is enabled.

Network activation waits until the restored VM passes its activation gate. Destination policy and connection limits may change host traffic admission, but they do not replace the captured guest identity.

References: crates/…/network.rs• L50-75 crates/…/coordinator.rs• L437-476 sdk/…/restore.rs• L149-164

TLS identity

Network interception uses a host-owned per-sandbox signing identity that stays outside the guest runtime mount. A full checkpoint carries only a host-sealed credential when the captured network resource proves that the managed signer was active.

Restore authenticates the sealed credential against the checkpoint root, the local wrapping key, and the captured signer fingerprint before it installs a new child-owned identity. Custom or unproven certificate paths do not authorize private-key export.

References: crates/…/tls_identity.rs• L26-95 crates/…/tls_receipt.rs• L98-170 crates/…/tls_receipt.rs• L227-249 crates/…/network.rs• L9-47

Restore coordination

Restore preparation

Restore creates child-owned state only after it validates the checkpoint closure and its expected identity. Full restore materializes the closure for eager memory and device restore, then creates a fresh writable disk head. Disk-only restore validates only the disk closure and skips memory and execution compatibility.

The child receives a root chain that is independent of the source's mutable head. The selected root layout must match the descriptor, and the child retains its own closure and managed-volume state for later cold boot.

References: sdk/…/restore.rs• L53-167 sdk/…/restore.rs• L362-429 sdk/…/restore.rs• L431-541

Restore activation

Activation publishes mount diagnostics, installs a fresh VM generation and clock identity, waits for guest acknowledgement, restores transport state, and then asks the workload to thaw. The relay enables public readiness only after the matching thaw response.

This order prevents restored application code from running before host mounts, VM identity, guest memory, and workload control state agree.

This diagram shows how a validated closure becomes an active sandbox.

sequenceDiagram
    participant L as Launcher
    participant V as VM
    participant R as Agent relay
    participant G as Guest workload
    L->>L: Validate closure and prepare restore sources
    L->>V: Install state and start paused
    V-->>L: Construction pause reached
    L->>L: Rebuild host resources and publish diagnostics
    L->>V: Install fresh generation and clock identity
    L->>V: Resume for activation
    V-->>L: Generation acknowledged
    L->>R: Install captured ready and transport state
    R->>G: Send workload thaw
    G-->>R: Return matching thaw acknowledgement
    R-->>L: Enable public readiness

References: crates/…/restore.rs• L279-360 crates/…/relay.rs• L1460-1709

Restore transport state

The guest-agent resource carries the captured protocol generation, host input position, input credit, guest bulk position, and workload attempt identity. Restore rejects a checkpoint when these values do not describe a complete transport boundary or when the captured protocol cannot perform workload thaw.

The relay restores the counters before thaw. It ignores stale control frames until it receives the matching response, so the application continues from the captured workload boundary instead of a new session boundary.

References: crates/…/restore.rs• L581-654 crates/…/relay.rs• L1581-1693

Change checklist

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

  • When the checkpoint manifest or resource treatment changes, update capture admission, closure validation, and restore device reconstruction together.
  • When execution-state or VM-generation policy changes, check pause-generation validation, local handoff metadata, restore activation, and full-restore override rules together.
  • When memory extent or object identity rules change, check baseline selection, object publication, cache materialization, and restore reads as one contract.
  • When disk journal, growth, or layer naming changes, check rollover, compaction, protected-layout admission, and restart recovery together.
  • When root or owned-volume paths change, check closure links, qcow backing names, journal authority, and missing-journal handling together.
  • When legacy migration rules change, check host bindings, no-follow acquisition, alias accounting, writer protection, recovery staging, and ready-marker publication together.
  • When archive preparation changes, check launch-staging ownership, abandoned-operation cleanup, private namespace checks, and final publication together.
  • When workload transport fields change, check guest freeze replies, restored agent validation, relay thaw, and public readiness together.
  • When external mounts, network bindings, or TLS identity evidence changes, check host authorization, checkpoint resource bindings, sidecar authentication, backend reports, and activation timing together.
  • When memory cache ownership or pruning rules change, check warm-cache pins, handoff locks, bounded sweep cursors, snapshot retention, and logical-space reporting together.
  • When root disk compaction changes, check prepared layers, journal commit order, backend adoption, old-layer retirement, and partial-commit recovery together.
  • When archive inventory or member transport checks change, keep the write allowlist, sparse ranges, member hashes, import validation, and atomic final-file replacement aligned.
  • When snapshot publication changes, keep private capture staging, source lineage commit, group generation exchange, source recovery reporting, and direct archive publication aligned.
  • When child disk materialization changes, keep root layout checks, source leases, private writable-head creation, backing-name relocation, and disk-only versus full restore policy aligned.
  • When owned-volume capture changes, keep canonical mount identity, descriptor inventory, layer integrity, private staging, and runtime journal publication aligned.

Important failure modes

TriggerConsequenceGuard
Guest freeze or required writeback does not reach the requested boundaryCapture stops before it claims a clean execution cut.The coordinator gates input, correlates the attempt, checks mount coverage, and waits for the bulk cut (crates/…/coordinator.rs• L1271-1391).
A device has no quiesce support or immutable-generation providerCheckpoint admission fails before VM state capture.Admission checks device inventory, quiesce support, filesystem providers, and additional-disk providers (crates/…/coordinator.rs• L2305-2376).
A disk journal is durable but backend replacement is uncertainThe source stays paused and restart follows the forward journal.Journal publication precedes backend replacement and post-journal errors are fail-closed (crates/…/disk.rs• L595-606).
Memory topology or baseline generation changes during an incremental captureThe delta is rejected or replaced with a complete capture.The coordinator compares generation and topology before it accepts an incremental plan (crates/…/coordinator.rs• L2001-2061).
A closure object or disk layer is missing, replaced, oversized, or has the wrong identityRestore cannot use the artifact.Closure admission checks bounded members and later reads recheck immutable identities (crates/…/resolver.rs• L162-269, crates/…/resolver.rs• L558-600).
A RAM backing is pinned or has a pending child handoffCache reclamation leaves it in place.Cleanup takes ownership locks, rechecks file identity, and reports protected states (crates/…/cache_storage.rs• L293-403).
Protected layout or legacy storage is incomplete or ambiguousActivation stops and requests migration or recovery.Layout admission uses bounded metadata, host bindings, real directories, and a durable ready sequence (crates/…/layout.rs• L109-159, crates/…/layout.rs• L191-210).
Captured network or TLS identity does not match the destinationFull restore cannot safely activate the network path.Restore validates the gateway identity and signer fingerprint before activation (crates/…/network.rs• L35-75, crates/…/tls_receipt.rs• L201-240).
VM Generation ID, clock activation, or workload thaw is unavailableThe restored workload stays fenced and public readiness is not announced.Capture admission requires the drivers, and activation waits for matching guest acknowledgements (crates/…/coordinator.rs• L2379-2397, crates/…/restore.rs• L591-654).
An archive member changes after admission or its transport bytes do not match the inventoryImport rejects the archive before it publishes a snapshot or child.The inventory binds descriptor identity and member transport integrity, and the loader uses a closed member set (sdk/…/archive.rs• L391-454, sdk/…/archive.rs• L1688-1851).
A full capture publishes an artifact but source recovery failsThe artifact is usable, but the operation reports source recovery failure instead of claiming a resumed source.Publication records the artifact separately from recovery status and never performs a second thaw (sdk/…/create.rs• L1317-1332, sdk/…/create.rs• L1038-1107).
A child root layer or owned-volume payload changes during materializationRestore fails without publishing partial child backing.Source leases, private staging, physical length checks, and integrity checks precede directory and journal renames (sdk/…/restore.rs• L431-541, sdk/…/owned.rs• L43-127).
A group publisher crashes before or during generation exchangeReaders see either the old complete group or the new complete group, not a batch prefix.Generation tests qualify the exchange, durability receipt, pending transaction, and retired-generation recovery (sdk/…/generation_tests.rs• L820-957).

Key files

FileWhy to read it
crates/…/coordinator.rsDefines the shared pause boundary, workload freeze, resource admission, memory capture, publication, and source recovery.
crates/…/resolver.rsDefines closure admission and the identity checks that make a checkpoint restorable.
crates/…/store.rsDefines immutable object publication and durable content identity.
crates/…/restore.rsDefines restore preparation, memory installation, device reconstruction, agent state, and mount diagnostics.
crates/…/disk.rsDefines root disk generations, forward recovery, growth, and compaction.
crates/…/cache_storage.rsDefines safe inspection and reclamation of local RAM backings.
crates/…/layout.rsDefines protected sandbox storage, activation guards, and ready-state publication.
crates/…/mod.rsDefines the public migration and recovery flow for legacy storage.
crates/…/io.rsDefines bounded no-follow source access and private disk capture.
crates/…/namespace.rsDefines host namespace authority for migration and preparation.
crates/…/launch_staging.rsDefines private staging ownership and abandoned preparation cleanup.
crates/…/network.rsDefines captured gateway and TLS signer identity checks.
crates/…/tls_identity.rsDefines host-owned per-sandbox interception credentials.
crates/…/tls_receipt.rsDefines sealed credential capture and authenticated restore.
crates/…/relay.rsDefines the activation gate, transport restoration, workload thaw, and readiness handoff.
sdk/…/create.rsConnects runtime capture to private artifact staging, source recovery reporting, installed publication, and direct archive publication.
sdk/…/archive.rsDefines archive inventory, sparse transport, member integrity, direct child materialization, and durable archive replacement.
sdk/…/copy.rsDefines private payload copies and the boundary between file snapshot copies and full checkpoint export.
sdk/…/restore.rsDefines child-owned full and disk-only checkpoint materialization and fresh writable disk heads.
sdk/…/owned.rsDefines reconstruction and validation of sandbox-owned disk and directory volumes.
sdk/…/generation_tests.rsQualifies atomic group exchange, durability outcomes, crash recovery, and reader visibility.