VM lifecycle and hypervisor backends
ArcBox runs a host guest VM and can run smaller sandbox VMs inside it. The host-side VMM builds the machine, connects its devices, and starts guest code through a platform hypervisor. The sandbox side uses one driver contract so the same workload flow can run on Firecracker without knowing the VMM behind it. See Virtualization platform for the wider platform view, Virtio devices for device behavior, Guest filesystem sharing for shared storage, and Computer runtime composition for the workload-facing composition.
System boundary
VM layers
The VM stack has two layers with different jobs. The host layer boots the main Linux guest that provides the ArcBox environment. The guest layer creates isolated microVMs for workloads inside that main guest.
| Layer | Main role | VM control path |
|---|---|---|
| Host VM | Boot and manage the ArcBox Linux guest | arcbox-vmm over arcbox-hypervisor |
| Sandbox VM | Isolate one workload inside the guest | arcbox-computer-runtime over arcbox-vm-driver |
| Sandbox init | Run commands and file actions inside one sandbox | arcbox-vm-agent over arcbox-vm-proto |
The two layers share the idea of a VM but not the same control interface. The host VMM talks to a platform hypervisor. The sandbox runtime talks to an adapter through a driver port, which keeps Firecracker-specific choices below the orchestration layer. (computer/…/lib.rs• L1-27)
References: virt/…/lib.rs• L1-20 virt/…/lib.rs• L1-34 computer/…/lib.rs• L1-27
Backend-neutral contract
arcbox-vm-driver defines the common shape of a VM before and after boot. A serializable VmSpec describes the VM identity, boot image, CPU and memory size, disks, NICs, vsock, shares, console, and isolation request. A VmDriver validates that description and turns it into a running VmHandle without exposing the selected VMM to the caller. (virt/…/lib.rs• L11-31, virt/…/driver.rs• L26-46)
The handle has a small required surface: identify the VM, observe its state and events, and stop it. Features that vary by backend use optional capabilities. A capability is available only when the driver supports it and the VM specification requested the related resource. (virt/…/driver.rs• L94-180, virt/…/capability.rs• L1-8)
| Common concern | Contract meaning |
|---|---|
| Identity | A stable VmRecord names the VM, driver, runtime area, and external process details when needed. |
| Ownership | A returned handle owns the VM and normally kills it when dropped. Detach releases ownership for a later adopter. |
| Observation | The handle reports Running, Quiesced, or Exited and emits one exit event. |
| Optional behavior | Vsock, staging, checkpoints, adoption, preparation, balloon, console, and diagnostics are discovered rather than assumed. |
The driver contract also makes two-phase startup a safe optimization. A driver that can prepare starts its VMM before it receives the full VM specification. Plain boot and restore must still have the same result as preparation followed by launch. The contract test kit checks this agreement and checks that capability flags match handle accessors. (virt/…/capability.rs• L33-42, virt/…/checks.rs• L61-90, virt/…/checks.rs• L285-314)
References: virt/…/lib.rs• L11-43 virt/…/driver.rs• L26-46 virt/…/driver.rs• L94-180 virt/…/capability.rs• L33-42 virt/…/checks.rs• L61-90
VM creation and execution
Host VM flow
The host VMM accepts a machine configuration and turns it into a bootable guest. It checks the basic CPU, memory, kernel, and vsock requirements before it creates platform state. Initialization then creates guest memory, registers the requested Virtio devices, prepares interrupt handling, and prepares the boot image and device description.
The start operation selects execution according to the host platform. Virtualization.framework runs the guest through Apple's managed VM runtime. KVM and the custom Hypervisor.framework path require the VMM to own vCPU execution. In all cases, the VMM exposes the same high-level lifecycle of initialize, start, pause, resume, stop, and reboot to its caller. (virt/…/mod.rs• L252-296, virt/…/mod.rs• L405-488, virt/…/mod.rs• L490-633)
This diagram shows how one host VM request becomes guest execution.
flowchart LR
A[VM configuration] --> B[VMM validation]
B --> C[Memory and Virtio setup]
C --> D[Kernel and guest boot data]
D --> E{Platform backend}
E --> F[Virtualization.framework managed execution]
E --> G[Hypervisor.framework vCPU execution]
E --> H[KVM vCPU execution]
F --> I[Running guest VM]
G --> I
H --> I
References: virt/…/mod.rs• L252-296 virt/…/mod.rs• L405-488 virt/…/linux.rs• L19-141 virt/…/setup.rs• L33-40
Sandbox VM flow
The sandbox runtime creates a VmSpec for each workload. It supplies the kernel, root disk, network attachment, and guest CID, then asks its NodeEnvironment for a VmDriver. The driver validates the spec, prepares the VMM and any private area, and returns a handle when the guest is running.
The standard sandbox composition uses FcDriver, the Firecracker adapter. It can prepare a VMM before a spec is available, stage the boot files, boot or restore the VM, and later expose the handle through the same driver contract. A failed boot releases the prepared VM, so a partial start does not leave an unmanaged VMM behind. (computer/…/environment.rs• L24-57, computer/…/spec.rs• L19-81, virt/…/driver.rs• L18-100, virt/…/prepared.rs• L25-48)
The sandbox boot path follows this order:
- Build and validate the workload VM specification.
- Acquire the network and storage inputs needed by that specification.
- Prepare the selected VMM and stage files when the driver requires a private area.
- Start or restore the VM through the driver.
- Reach the guest agent and wait for its readiness signal.
- Use the handle for workload execution, file work, checkpoint work, or shutdown.
Preparation binds the readiness listener before the guest starts. This prevents a guest that dials out during boot from racing past the host listener. The prepared process also records its identity before the guest runs, which gives restart handling a durable way to find and manage it. (virt/…/prepared.rs• L79-99, virt/…/prepared.rs• L192-226, virt/…/capability.rs• L72-91)
References: computer/…/environment.rs• L24-57 computer/…/spec.rs• L36-81 virt/…/capability.rs• L33-42 virt/…/capability.rs• L72-102 virt/…/driver.rs• L18-100 virt/…/prepared.rs• L25-48
Guest control channels
arcbox-vm-proto defines the small wire contract between the host-side sandbox runtime and vm-agent inside the sandbox. It keeps the agent independent from the manager while ensuring that both sides use the same frame and payload rules.
The exec channel carries workload start requests, input, output, terminal changes, signals, clock sync, network repair, and port-wait commands. The file channel carries file reads and writes plus metadata, directory operations, and watch events. Both channels use a typed frame with a length and payload. (virt/…/lib.rs• L1-28, virt/…/exec.rs• L4-79, virt/…/file.rs• L1-34)
The guest agent listens for those channels after it mounts its basic guest filesystems and sets up guest DNS. It signals readiness only after the exec and file listeners are ready. It also keeps the guest wall clock aligned with the host through the hypervisor's PTP clock at startup and before accepted work connections. This matters after restore because a snapshot can contain an old wall-clock value. (virt/…/main.rs• L17-22, virt/…/main.rs• L2011-2036, virt/…/main.rs• L2042-2064)
Workload execution stays inside the guest agent boundary. A start request becomes either a piped process session or an interactive terminal session. The agent streams output and sends a final exit result. As guest PID 1, it also reaps workload children so the host receives a usable result instead of a stranded process. (virt/…/main.rs• L1294-1312, virt/…/main.rs• L1314-1355, virt/…/main.rs• L1461-1627, virt/…/main.rs• L1653-1859)
The readiness and workload path connects the VM lifecycle to the guest process lifecycle.
sequenceDiagram
participant Host as Sandbox runtime
participant VMM as VM driver and VMM
participant Agent as vm-agent
participant Workload as Guest process
Host->>VMM: Boot or restore VM
VMM-->>Host: Running handle
Agent->>Host: Readiness dial-out
Host->>Agent: Start request over exec channel
Agent->>Workload: Spawn process
Workload-->>Agent: Output and exit
Agent-->>Host: Framed output and exit result
References: virt/…/lib.rs• L1-28 virt/…/exec.rs• L4-79 virt/…/main.rs• L2011-2064 virt/…/main.rs• L1314-1355 virt/…/main.rs• L1461-1627
Hypervisor backends
Virtualization.framework
Virtualization.framework is the default macOS execution path for the host VM. It accepts a complete VM configuration with the boot loader and devices, then manages vCPU execution and lifecycle work inside Apple's runtime. The VMM waits for framework completion for start, pause, resume, and stop instead of running a vCPU loop itself.
This path is suited to the stable, managed VM model. Its device set is configured through the framework, including storage, network, serial, vsock, entropy, shared directories, and graphics where the guest needs them. The framework and host entitlement must be available before a VM can start. (virt/…/darwin.rs• L24-207, virt/…/virtual_machine.rs• L18-25, virt/…/vm.rs• L130-240)
macOS does not provide the same hardware dirty-page tracking as KVM. The hypervisor layer therefore supports a software view of dirty memory by recording page checksums and comparing them later. This gives snapshot flows a way to identify changed pages, with higher cost than hardware tracking. (virt/…/memory.rs• L62-77, virt/…/memory.rs• L328-428)
References: virt/…/config.rs• L120-139 virt/…/darwin.rs• L24-207 virt/…/hypervisor.rs• L31-115 virt/…/vm.rs• L130-240 virt/…/memory.rs• L62-77
Hypervisor.framework
Hypervisor.framework is the custom macOS backend. It gives the VMM direct control of guest memory mapping, device MMIO, interrupts, and vCPU threads. The VMM creates the guest boot state and then runs each vCPU until an exit occurs, handling device access and guest power requests between exits.
This backend exists where the VMM needs control that managed execution does not expose. Its lifecycle includes explicit vCPU wake-up and worker coordination, so device activity can wake a guest that is waiting for an interrupt. It is selected as a macOS backend and requires the host support described by the VMM configuration. (virt/…/setup.rs• L33-40, virt/…/mod.rs• L1-15, virt/…/lifecycle.rs• L11-17)
arcbox-hv is the lower binding layer for this backend. It provides the VM handle, vCPU handle, memory map, exit reasons, and interrupt controller needed by the custom VMM. It is a macOS ARM64 layer and is not the driver port used for Firecracker. (virt/…/lib.rs• L1-24, virt/…/vm.rs• L14-116)
References: virt/…/setup.rs• L33-40 virt/…/mod.rs• L1-15 virt/…/lifecycle.rs• L11-17 virt/…/lib.rs• L1-24 virt/…/vm.rs• L14-116
Firecracker
Firecracker is the external VMM used for nested sandbox VMs. arcbox-fc-driver translates the backend-neutral VmSpec into Firecracker configuration, starts and owns the Firecracker process, and returns a VmHandle through the driver port. The sandbox runtime does not need to know whether the process runs directly or under the jailer. (virt/…/driver.rs• L18-33, virt/…/prepared.rs• L25-48)
The adapter supports warm preparation, file staging, checkpoints when jailer isolation is available, and adoption after the original manager exits. A jailed process records its actual jail as part of its durable VM record. This lets later cleanup and adoption use the area created by the original launch instead of guessing from current configuration. (virt/…/driver.rs• L56-133, virt/…/prepared.rs• L79-99, virt/…/driver.rs• L359-416)
Firecracker path handling has two views. The host uses absolute paths for its sockets and staged files. Firecracker sees paths inside its jail. The renderer keeps those views aligned and stages files before launch. Writable disks are private copies or device nodes, while files that the caller hands over can move into the VM area. (virt/…/render.rs• L43-55, virt/…/render.rs• L188-224, virt/…/jail.rs• L395-428)
Restore is a controlled relaunch rather than a direct reuse of the old VM. The image format must belong to Firecracker and the restore must use jailer isolation. The guest stays frozen while the adapter reconnects its disks and network devices to the new VM, then resumes with the new host attachments. (virt/…/render.rs• L332-435, virt/…/prepared.rs• L229-271)
Adoption has a safe reduced form. The driver first verifies that a live process is the Firecracker instance named by the record. If the API socket answers, it rebuilds a full handle with device state. If the API is missing or does not answer within the bound, it still returns a process-only handle that can observe, kill, detach, and access the recorded staging area. It does not pretend to provide API-dependent features. (virt/…/discover.rs• L1-21, virt/…/adopt.rs• L1-14, virt/…/adopt.rs• L39-86, virt/…/process_only.rs• L1-16)
This diagram shows the Firecracker path from durable identity to a usable handle.
flowchart LR
A[VM record or new VM spec] --> B{New or adopted}
B -->|New| C[Prepare Firecracker process]
C --> D[Render config and stage files]
D --> E[Boot or restore]
B -->|Adopt| F[Verify process identity]
F --> G{API responds}
G -->|Yes| H[Rebuild full handle]
G -->|No| I[Rebuild process-only handle]
E --> J[Running VM handle]
H --> J
I --> K[Observable killable handle]
References: virt/…/driver.rs• L50-133 virt/…/prepared.rs• L51-115 virt/…/render.rs• L188-224 virt/…/render.rs• L332-435 virt/…/discover.rs• L29-59 virt/…/adopt.rs• L39-86 virt/…/process_only.rs• L31-125
Lifecycle controls
State transitions
The driver port presents a small state model that callers can use across backends. A VM is Running while it executes, Quiesced when a checkpoint holds it frozen, and Exited once it is gone with its exit status. Backend-specific phases stay below this model. (virt/…/driver.rs• L250-285)
An ordinary shutdown is terminal for that VM instance. A graceful shutdown asks the guest to stop and kills it at the deadline if needed. A kill stops it without asking the guest. A reset is an event for the orchestrator to interpret, often as a fresh stop-and-boot. The exit event is delivered once, while a later observer can still read the final state. (virt/…/driver.rs• L110-124, virt/…/driver.rs• L276-285, virt/…/checks.rs• L31-59)
Optional capabilities
The driver contract separates core lifecycle control from features that vary by backend. A caller checks the capability advertised by the driver and then uses the handle accessor only when the VM specification also requested the related resource.
| Capability | Product use |
|---|---|
| Vsock and listener | Reach the guest agent and receive guest readiness or other guest-initiated connections. |
| Staging | Place kernels, disks, and checkpoint data where a confined VMM can read them. |
| Checkpoint | Freeze a VM long enough to save state, then resume it or leave it quiesced. |
| Adopt and detach | Let an external VMM survive its original process and be found again. |
| Balloon, console, and debug | Use backend-specific memory, output, or diagnostic support when present. |
Staging is available through both sides of a prepared VM: the prepared process before boot and the handle after boot. An adopted Firecracker handle can still reach the same area because the record preserves the jail. A disk that must outlive the VM must leave that area before the VM is discarded. (virt/…/capability.rs• L105-184, virt/…/driver.rs• L149-163, virt/…/process_only.rs• L114-125)
This design makes backend gaps visible at capability discovery instead of late in a workload flow. For example, Firecracker provides vsock, staging, preparation, and adoption. Its checkpoint capability depends on jailer configuration, and it does not claim a console, balloon, or debug snapshot. (virt/…/driver.rs• L56-73, virt/…/driver.rs• L183-220, virt/…/checks.rs• L61-90)
References: virt/…/driver.rs• L183-220 virt/…/capability.rs• L105-184 virt/…/driver.rs• L56-73 virt/…/process_only.rs• L70-125 virt/…/checks.rs• L61-90
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the host VMM's backend selection aligned with the boot contract. The custom Hypervisor.framework path uses different early console assumptions from Virtualization.framework. (engine/…/boot.rs• L674-698)
- Keep
VmSpecfields, driver capability flags, and handle accessors aligned. A spec can request a feature that the selected driver does not expose. - Keep preparation equivalent to plain boot and restore. A warm process must produce the same record, state, and capabilities as a direct launch. (virt/…/capability.rs• L33-42, virt/…/checks.rs• L285-314)
- Keep the readiness listener bound before a prepared guest starts. A guest dial-out during boot must not be lost. (virt/…/capability.rs• L72-76, virt/…/prepared.rs• L192-226)
- Keep Firecracker path rendering and staging as one contract. A path that is valid for the host is not automatically visible inside a jailer area. (virt/…/render.rs• L188-224, virt/…/capability.rs• L105-138)
- Keep the durable jail record with adoption and cleanup. Recomputing a jail from changed node configuration can target the wrong VM area. (virt/…/driver.rs• L359-416, virt/…/adopt.rs• L89-102, virt/…/driver.rs• L170-196)
- Treat readiness and protocol changes as a host-agent contract change. The readiness port, exec port, file port, frame types, and payload defaults must remain readable by older agents used by restored snapshots. (virt/…/lib.rs• L15-27, virt/…/main.rs• L24-35)
- Keep guest time recovery before workload and file requests. A restored guest must not use snapshot-era time for process results or file metadata. (virt/…/main.rs• L223-244, virt/…/main.rs• L2042-2064)
- Keep checkpoint format and restore isolation rules together. Firecracker restores only its own full checkpoint format and requires the private jailed layout for disk reattachment. (virt/…/render.rs• L332-360, virt/…/prepared.rs• L245-271)
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| CPU count is zero, memory is below the VMM minimum, or a required kernel path is absent | VM creation stops before the platform VM is built | Validate VmmConfig or VmSpec before backend setup. (virt/…/mod.rs• L258-278, virt/…/spec.rs• L213-228) |
| Virtualization.framework is unavailable or its VM configuration is outside host limits | The macOS managed backend cannot create or start the host VM | Probe framework support and validate platform capabilities before creation. (virt/…/hypervisor.rs• L31-43, virt/…/hypervisor.rs• L117-166) |
| Hypervisor.framework is asked to run without its supported macOS ARM64 environment | The custom host VMM cannot provide its VM or vCPU execution path | Select a supported backend and keep the platform-specific binding gated. (virt/…/lib.rs• L1-24, virt/…/config.rs• L120-139) |
| A Firecracker spec requests a feature the adapter does not expose | Sandbox boot is rejected as an invalid spec | Check driver capabilities and keep unsupported console, share, and balloon requests out of the Firecracker spec. (virt/…/driver.rs• L60-73, virt/…/render.rs• L246-265) |
| A Firecracker jail path is too long for its Unix sockets | The VMM starts but host connections fail and boot appears to time out | Ask the driver for its ID budget and keep generated IDs within the layout limit. (virt/…/driver.rs• L71-90, virt/…/jail.rs• L178-210) |
| A sandbox agent never reaches readiness or speaks an incompatible protocol | The sandbox boot cannot complete its readiness phase | Bind the listener before boot and use the readiness event plus protocol handshake before treating the VM as ready. (virt/…/prepared.rs• L192-226, virt/…/main.rs• L2030-2036, virt/…/exec.rs• L33-42) |
| An adopted Firecracker API socket is missing or wedged | The VM loses device-dependent operations but remains manageable | Fall back to a process-only handle within the bounded adopt period, then kill or detach through the process record. (virt/…/adopt.rs• L31-86, virt/…/process_only.rs• L70-125) |
| A restore uses a foreign or diff checkpoint, or lacks jailer isolation | Restore is refused before it can attach guest state | Match the Firecracker full format and use jailed staging for the image and replacement disks. (virt/…/render.rs• L332-360, virt/…/driver.rs• L84-99) |
| A restored guest keeps snapshot-era wall-clock time | Workloads and file metadata use incorrect time until a later sync | Sync from ptp_kvm at startup and before accepted guest work. (virt/…/main.rs• L142-150, virt/…/main.rs• L223-244) |
Key files
| File | Why to read it |
|---|---|
| virt/…/mod.rs | Main host VMM lifecycle and the dispatch between platform execution modes. |
| virt/…/config.rs | Host VM inputs, backend selection, and VMM state vocabulary. |
| virt/…/darwin.rs | Managed Virtualization.framework host path and device setup. |
| virt/…/setup.rs | Custom Hypervisor.framework VM setup and boot preparation. |
| virt/…/lifecycle.rs | Custom backend start and stop behavior. |
| virt/…/traits.rs | Platform-neutral hypervisor, VM, vCPU, and guest-memory boundary. |
| virt/…/memory.rs | macOS guest memory and software dirty-page view used by snapshot support. |
| virt/…/vm.rs | Virtualization.framework VM lifecycle exposed to the Rust layer. |
| virt/…/vm.rs | Hypervisor.framework VM lifetime, memory mapping, and vCPU exits. |
| virt/…/spec.rs | Backend-neutral per-VM description and validation rules. |
| virt/…/driver.rs | Common driver and handle contract across VMM adapters. |
| virt/…/capability.rs | Optional behavior for preparation, staging, checkpoints, vsock, and adoption. |
| virt/…/checks.rs | Cross-driver guarantees for lifecycle, capabilities, adoption, staging, and restore. |
| virt/…/driver.rs | Firecracker boot, restore, prepare, adoption, and capability behavior. |
| virt/…/prepared.rs | Firecracker process preparation, readiness listener, and transition into a running handle. |
| virt/…/discover.rs | Process identity checks used to find an orphaned Firecracker VM. |
| virt/…/adopt.rs | Full-handle and process-only adoption paths. |
| virt/…/render.rs | Translation from VM specs to Firecracker paths and API plans. |
| virt/…/jail.rs | Firecracker confinement area and file movement rules. |
| virt/…/exec.rs | Guest readiness and workload control channel. |
| virt/…/file.rs | Guest file operation channel and event contract. |
| virt/…/main.rs | Guest readiness, time sync, workload execution, and child reaping. |
| computer/…/environment.rs | Composition point that supplies the VM driver to the sandbox runtime. |
| computer/…/spec.rs | Translation from a sandbox workload into a driver VM specification. |