Images and snapshots
Images provide the stable boot content for machines and sandboxes. Snapshots preserve a running sandbox so the system can create a matching workload quickly or recover the same workload after a pause. Together they separate reusable source state from per-workload changes while keeping the files needed for restore alive for as long as a catalog entry depends on them. The wider system model is described in workload engine, while the boot and execution flow is described in engine orchestration and computer runtime.
Image acquisition
Image acquisition turns a published or local source into a checked local boot image. The source is resolved before large data transfer, the result is checked against its declared identity and content, and only a complete image becomes available to workload creation.
Linux machine images
Linux machine images provide versioned distribution root filesystems for machine creation. A machine request selects a distribution, release, and architecture. The machine service resolves the selection and obtains the matching rootfs before it registers the machine (app/…/machine.rs• L64-117).
The published index separates a moving latest choice from immutable version entries. A pull can follow the latest entry or use an explicit version. Host architecture names are mapped to the image registry's architecture names before resolution (engine/…/machine_image.rs• L43-59, engine/…/machine_image.rs• L268-331).
The local registry keeps the manifest beside the rootfs. The manifest records the image identity, source information, format, size, and SHA-256 digest. The rootfs is streamed into a temporary area and is accepted only when its size and digest match. The completed area is then moved into the registry as one unit, so a failed or cancelled pull does not look like a usable image (engine/…/machine_image.rs• L102-149, engine/…/machine_image.rs• L216-240, engine/…/machine_image.rs• L268-331).
References: app/…/machine.rs• L64-117 engine/…/machine_image.rs• L43-59 engine/…/machine_image.rs• L102-149 engine/…/machine_image.rs• L216-240 engine/…/machine_image.rs• L268-331
macOS base images
macOS base images provide an installed system disk and the small boot data that must travel with it. The product normally obtains them from a published manifest. An optional IPSW install path can create the same kind of base image from a local or downloaded restore image (app/…/pull.rs• L1-10, app/…/install.rs• L1-11).
The published macOS path validates the host hardware model before downloading the large disk. It reconstructs a sparse system disk from verified chunks, verifies auxiliary storage, and records the hardware model and machine identity with the result. The image is published only after all required artifacts pass their checks (app/…/pull.rs• L107-169, app/…/pull.rs• L172-268).
Each VM receives a disposable instance derived from the base. The large system disk is copy-on-write cloned when the host file system supports it. Auxiliary storage and identity data are copied so the instance remains bootable with the base's installed system (app/…/image.rs• L60-123).
References: app/…/pull.rs• L1-10 app/…/pull.rs• L107-169 app/…/pull.rs• L172-268 app/…/install.rs• L1-11 app/…/image.rs• L60-123
Sandbox rootfs preparation
Sandbox rootfs preparation converts an image source into a bootable writable starting point. It supports OCI image layouts, Docker layer directories, and a built-in default image. The preparation step also supplies the guest agent that makes the sandbox usable after boot (computer/…/rootfs.rs• L1-19).
Converted rootfs images
The rootfs builder caches one ext4 result for the image layer and the injected guest-agent content. A cache hit avoids another conversion. A new result is built beside the cache and renamed into place only when the conversion and agent injection finish (computer/…/rootfs.rs• L117-215).
The cache is not the owner of every rootfs file. A live sandbox may still use an older conversion, and a snapshot may need the exact bytes that existed when its guest memory was captured. The runtime therefore supplies the rootfs files referenced by snapshots and templates as pins during cache cleanup. This prevents an apparently old image from being removed while a restore still needs it (computer/…/rootfs.rs• L236-295, computer/…/checkpoint.rs• L32-45).
References: computer/…/rootfs.rs• L117-215 computer/…/rootfs.rs• L236-295 computer/…/checkpoint.rs• L32-45
Rootfs isolation
The sandbox runtime gives each workload a private view of its rootfs. When the host can provide a block-level copy-on-write view, the shared template remains read-only and sandbox writes go into a sparse overlay. If that view cannot be used for the VM, the runtime falls back to a private rootfs copy (engine/…/snapshot_cow.rs• L1-14, computer/…/boot.rs• L130-213).
This separation lets many sandboxes start from the same image without copying all source blocks. The overlay is part of the workload's live disk state. It is deleted during normal teardown, but it is retained across pause so resume can recreate the same disk view (engine/…/snapshot_cow.rs• L327-345, engine/…/snapshot_cow.rs• L687-743).
The CoW manager also treats resource records as part of recovery. It tracks shared template attachments, identifies the owner of each overlay, and adopts resources for sandboxes that are still running after a restart. Startup removes only resources that are neither live nor retained for pause. It verifies the backing file before detaching a stale loop device, so a reused device is not detached by mistake (engine/…/persistence.rs• L38-99, engine/…/persistence.rs• L147-239, engine/…/persistence.rs• L308-395).
References: engine/…/snapshot_cow.rs• L1-14 engine/…/snapshot_cow.rs• L327-345 engine/…/snapshot_cow.rs• L600-743 engine/…/persistence.rs• L38-99 engine/…/persistence.rs• L147-239 engine/…/persistence.rs• L308-395 computer/…/boot.rs• L130-213
Snapshot capture
A snapshot is a checkpoint of a fully booted sandbox. It captures the VM state and memory together with the information needed to rebuild the disk, network mode, and VM shape on another restore. The public checkpoint operation requires a ready sandbox with no active execution and returns a reusable snapshot identifier (rpc/…/snapshot.proto• L18-35, rpc/…/snapshot.proto• L38-58).
When a checkpoint starts, the runtime freezes the guest through the VM driver. It writes the capture into a private staging area, settles the guest as requested, and records the source kernel, rootfs, network identity mode, VM geometry, and checkpoint format. A normal checkpoint resumes the guest after capture. A pause checkpoint keeps it quiesced because later disk writes would diverge from the saved memory (computer/…/checkpoint.rs• L112-156, computer/…/checkpoint.rs• L159-220).
The catalog publishes a snapshot by renaming a complete staging directory into the snapshot namespace. Readers therefore see either a complete snapshot or no snapshot. A failed operation removes its temporary data, and startup cleanup removes temporary directories left by a process crash (engine/…/snapshot.rs• L206-217, engine/…/snapshot.rs• L236-281, engine/…/snapshot.rs• L389-418).
The capture and restore contract is summarized below.
flowchart LR
A[Ready sandbox] --> B[Freeze guest]
B --> C[Write VM state and memory]
C --> D[Record restore metadata]
D --> E{Checkpoint purpose}
E -->|Reusable checkpoint| F[Resume guest]
E -->|Pause state| G[Keep guest quiesced]
F --> H[Publish snapshot]
G --> H
Snapshot restoration
Snapshot restoration creates a new sandbox from a published checkpoint or brings a paused sandbox back under its original identity. Both paths rebuild runtime resources before they report the sandbox ready. A new-sandbox restore uses a fresh disk overlay. A pause resume reuses the retained overlay because it must preserve the sandbox's writes (computer/…/restore.rs• L1-9, computer/…/pause.rs• L1-23).
New sandbox restoration
The restore service validates the source and target identity, reserves the new sandbox, and then restores the VM state. It stages the recorded boot inputs into the new VM's area, rebuilds the rootfs view, loads the snapshot, and applies the network identity required by the new sandbox. The new sandbox reaches READY only after these resources are owned and recorded (app/…/snapshot.rs• L66-89, computer/…/checkpoint.rs• L135-188, computer/…/restore.rs• L101-107).
Snapshots created with the invariant network identity need only a new host-side network attachment. Older snapshots require a guest network reconfiguration before the restore can succeed. This distinction prevents a restored guest from claiming its source sandbox's address (computer/…/restore.rs• L331-365, computer/…/restore.rs• L395-447).
The runtime may prepare restore slots in advance. A slot contains the staged kernel, rootfs view, and checkpoint data. A later restore can claim that slot and perform only the remaining load and guest setup work. A successful restore starts background refill for that snapshot, while a dead or failed slot is discarded (computer/…/pool.rs• L190-235, computer/…/pool.rs• L278-369).
References: app/…/snapshot.rs• L66-89 computer/…/checkpoint.rs• L135-188 computer/…/restore.rs• L101-107 computer/…/restore.rs• L331-365 computer/…/restore.rs• L395-447 computer/…/pool.rs• L190-235 computer/…/pool.rs• L278-369
Paused sandbox resumption
Pause is a lifecycle state rather than a user checkpoint that can seed an unrelated sandbox. The pause operation saves the guest state and keeps the writable disk overlay, then releases the VM and network resources. Resume reassembles that overlay and checkpoint under the same sandbox ID, allocates fresh network state, and removes the pause checkpoint after the sandbox is running again (computer/…/pause.rs• L34-52, computer/…/restore.rs• L171-256).
Copy-mode pause parks the private rootfs before the VM is released. This preserves the only writable disk when a block-level overlay was not available. A pause that cannot preserve its disk is refused instead of creating a state that cannot resume (computer/…/pause.rs• L39-51, computer/…/pause.rs• L59-105).
References: computer/…/pause.rs• L34-52 computer/…/restore.rs• L171-256 computer/…/pause.rs• L39-51 computer/…/pause.rs• L59-105
Warm snapshot reuse
Warm snapshots reduce the time needed to create common sandbox shapes. The first eligible cold boot reaches ready, publishes an ordinary snapshot with a reserved warm key, and later creates restore that snapshot instead of repeating the boot. The cache is a use of the snapshot catalog rather than a separate storage system (computer/…/warm.rs• L1-15).
The warm key represents the effective boot shape and the content identity of the kernel and rootfs. It changes when the boot recipe, VM geometry, or boot input content changes. Only compatible, jailer-isolated, networked creates without caller-specific boot or mount state can use this cache (computer/…/warm.rs• L24-109).
Warm publishing is single-flight per key and keeps a small set of recently used keys. Replacement and eviction delete the old snapshot only after any prepared restore slots that use it are drained. A failed warm publish does not fail an otherwise healthy cold boot unless capture leaves the guest unusable (computer/…/warm.rs• L99-147, computer/…/warm.rs• L174-236).
References: computer/…/warm.rs• L1-15 computer/…/warm.rs• L24-109 computer/…/warm.rs• L99-147 computer/…/warm.rs• L174-236
Template snapshot ownership
Templates provide named, versioned sandbox bases. A template can refer to a converted rootfs and an optional pre-warmed snapshot that reaches the boot-ready point. The template catalog stores metadata and references these artifacts instead of copying them into the catalog (engine/…/template_catalog.rs• L1-16, engine/…/template_catalog.rs• L85-123).
Build installs a mutable draft. Publish freezes that draft as an immutable version. A bare template name resolves to the newest published version. If no version is published, it resolves to the draft. A resolved entry also has a content digest and a canonical reference that pins the name, version, and content for idempotent workload creation (engine/…/template_catalog.rs• L13-16, engine/…/template_catalog.rs• L126-166, engine/…/template_catalog.rs• L219-307).
A user checkpoint can be promoted into template ownership by making a separate snapshot copy. The copy receives a reserved ownership label, keeps the source rootfs reference, and can outlive the user checkpoint. Template deletion and version changes report snapshots that no catalog entry still owns so the runtime can reclaim them (computer/…/templates.rs• L88-148, engine/…/template_catalog.rs• L190-205, engine/…/template_catalog.rs• L323-367).
Template artifact release happens after the catalog mutation is durable. The catalog compares removed warm snapshot IDs with all remaining entries before it reports them for deletion. If a later catalog-wide scan cannot read a record, it keeps the artifact and logs the candidate rather than risking deletion of a snapshot that another entry still uses (engine/…/template_catalog.rs• L387-435).
Template prewarming boots the built rootfs once and captures it at ready. A create uses that snapshot only when its requested VM geometry matches the capture geometry. This protects the VM memory restore contract while allowing the same template to cold-boot when the requested shape is different (computer/…/templates.rs• L151-177, engine/…/template_catalog.rs• L85-96).
References: engine/…/template_catalog.rs• L1-16 engine/…/template_catalog.rs• L85-123 engine/…/template_catalog.rs• L126-166 engine/…/template_catalog.rs• L219-307 engine/…/template_catalog.rs• L323-435 computer/…/templates.rs• L88-177
Storage ownership
Storage ownership follows the lifecycle object that needs an artifact. Image registries own acquired base images. The rootfs cache owns generated boot images until live sandboxes, snapshots, or templates pin them. The snapshot catalog owns checkpoint files and their metadata. Template records own references to template rootfs and warm snapshots, while the runtime owns the cleanup actions that remove released artifacts.
The snapshot catalog records enough context to make that ownership safe across restarts. It can list or delete snapshots, find a snapshot by ID, remove incomplete captures, and return every rootfs path still referenced by a snapshot. A corrupt catalog record is treated as an error during reference collection rather than as an empty reference, because guessing could delete data needed by restore (engine/…/snapshot.rs• L303-317, engine/…/snapshot.rs• L353-490).
The CoW manager keeps ownership balanced across setup, pause, restore, teardown, and restart. It removes a per-sandbox device and overlay only after the device and loop references are released. If setup cleanup fails, it records the remaining resources for retry. A failed setup must not delete an overlay it did not create, and a pause must not delete the overlay that represents the sandbox's retained disk (engine/…/snapshot_cow.rs• L600-743, engine/…/persistence.rs• L400-505).
Snapshot data is private to the data directory. Published snapshot directories and their files use restricted permissions, and the publish step syncs the files and directories before making the snapshot visible. This protects both workload memory state and the recovery record that describes it (engine/…/snapshot.rs• L135-166, engine/…/snapshot.rs• L262-280).
The main lifecycle is shown here.
sequenceDiagram
participant Source as Image source
participant Prep as Image and rootfs preparation
participant Run as Sandbox runtime
participant Catalog as Snapshot catalog
participant Store as Rootfs and CoW storage
Source->>Prep: Resolve and verify image
Prep->>Store: Cache bootable rootfs
Run->>Store: Create private disk view
Run->>Catalog: Capture VM state and memory
Catalog->>Store: Pin exact rootfs origin
Catalog-->>Run: Snapshot ID
Run->>Catalog: Restore snapshot
Catalog-->>Run: Snapshot files and restore metadata
Run->>Store: Rebuild disk view
Run-->>Run: Ready restored workload
Change checklist
When these files or sections are changed, remember to consider these:
- Change the image manifest or selector rules together with the local registry's integrity and identity checks. A selector that resolves to a different stream or format can produce a valid-looking but wrong boot source.
- Change snapshot metadata fields together with restore staging and compatibility checks. In particular, VM geometry, checkpoint format, rootfs path, and network identity mode must remain aligned between capture and restore.
- Change rootfs cache naming or cleanup rules together with snapshot and template reference scans. Reclaim must recognize every path that a durable catalog can still require.
- Change pause or resume storage behavior together with the retained overlay path and restart reconciliation. A mismatch can leave a paused sandbox listed but without its writable disk.
- Change reserved snapshot labels or names together with user listing, deletion, template ownership, and warm-cache lookup. These labels define storage ownership across public and internal surfaces.
- Change CoW setup or rollback checks together with device discovery and orphan cleanup. Device-mapper can keep a live snapshot even when its
/dev/mappernode is missing. - Change template draft, publish, or digest rules together with canonical create references and released-artifact scanning. A retry must not select changed content or delete a warm snapshot still referenced by another entry.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Image bytes do not match the manifest size or digest | The image is rejected and no broken registry entry is exposed | Verify the downloaded content before the staging directory is published (engine/…/machine_image.rs• L447-504, app/…/pull.rs• L270-317) |
| Snapshot restore runs without jailer isolation | Restore cannot safely relocate paths recorded by the checkpoint | Require jailer mode for checkpoint restore, pause, and prewarm (computer/…/checkpoint.rs• L183-188, computer/…/pause.rs• L114-126) |
| A snapshot's rootfs origin is removed from the cache | The memory image and disk view no longer describe the same guest | Pin rootfs paths from both snapshots and templates during cache cleanup (computer/…/checkpoint.rs• L32-45, engine/…/template_catalog.rs• L369-384) |
| A pause cannot preserve the writable rootfs | The sandbox would enter a paused state that cannot resume | Park the copy-mode rootfs before VM release or refuse the pause (computer/…/pause.rs• L59-105) |
| Restore network setup does not match the snapshot's addressing mode | The restored sandbox may claim the source address or fail to receive its new address | Record the mode at capture and use it to choose host-only or guest readdressing (computer/…/restore.rs• L395-447) |
| A warm snapshot uses changed boot inputs or VM geometry | Create may restore stale or incompatible guest state | Include boot inputs, content fingerprints, and geometry in the warm key (computer/…/warm.rs• L29-85) |
| CoW setup fails after device-mapper creates a device without a node | The live device can remain attached and unrecorded | Check device-mapper state by device name during rollback. Do not use only the /dev/mapper node (engine/…/snapshot_cow.rs• L82-103, engine/…/persistence.rs• L400-432) |
| A template or overlay owner record is removed too early | Restart cleanup can detach a live loop or delete a paused sandbox's disk | Write ownership markers durably and reconcile only after checking live and retained owners (engine/…/persistence.rs• L147-239, engine/…/persistence.rs• L249-365) |
| A template catalog scan fails after a committed mutation | Artifact release is skipped and an orphan warm snapshot may remain | Keep the committed catalog change and reclaim the logged candidate only after the catalog parses cleanly (engine/…/template_catalog.rs• L387-409) |
Key files
| File | Why to read it |
|---|---|
| engine/…/machine_image.rs | Linux machine image selection, verification, and local registry ownership |
| engine/…/remote_image.rs | Shared published-image reference and staging model |
| app/…/pull.rs | macOS manifest resolution, host checks, decompression, and atomic image landing |
| app/…/image.rs | macOS base-image artifacts and per-VM copy-on-write cloning |
| computer/…/rootfs.rs | Sandbox image conversion, guest-agent preparation, cache reuse, and reclamation inputs |
| engine/…/snapshot.rs | Snapshot metadata, atomic publication, catalog queries, and rootfs pins |
| engine/…/snapshot_cow.rs | Shared template disk views, retained writable overlays, and resource teardown |
| engine/…/persistence.rs | Restart adoption, durable ownership markers, orphan reconciliation, and cleanup retry state |
| computer/…/checkpoint.rs | Guest freeze, capture, settlement, and snapshot metadata creation |
| computer/…/restore.rs | New-sandbox restore staging and guest reconfiguration |
| computer/…/pause.rs | Disk retention rules for pause and resume recovery |
| computer/…/warm.rs | Warm snapshot lookup, publication, replacement, and eviction |
| engine/…/template_catalog.rs | Template drafts, immutable versions, content pins, artifact references, and ownership release |
| app/…/snapshot.rs | Public checkpoint, restore, list, and delete service boundary |