Introducing a new way to review your PRs.

Read the announcement

arcboxlabs / arcbox

Run AI agents on real and isolated machines — own kernel, filesystem, and network — with <100ms boot. Local first, OCI compatible, pure Rust.

View on GitHub

32 documents · Updated Nov 6, 2026

docs / virtualization-platform

Virtualization platform

The virtualization platform runs ArcBox workloads in isolated virtual machines. It gives higher layers one VM contract while connecting each request to a monitor, a host hypervisor or external VMM, guest devices, and controlled host services.

System role

The platform separates workload intent from the host mechanism that executes it. A caller describes the guest's resources, boot inputs, disks, networks, and optional services. A VM driver validates that request, selects a VMM, and returns a handle that remains the common control point for identity, observation, shutdown, restore, and supported optional features.

The main system boundaries are:

BoundarySystem responsibility
VM driver contractGives orchestration one way to create, observe, stop, restore, and recover VMs.
VM monitor or VMM adapterTurns the request into guest memory, CPU execution, boot state, devices, and runtime events.
Hypervisor backendProvides host-side CPU and memory isolation.
Device modelPresents guest hardware and carries guest I/O to host services.
Host integrationSupplies storage, network paths, file access, control channels, and other resources outside the guest.

The same contract covers in-process monitors and external VMM processes. This lets workload orchestration choose a backend without changing its VM control model. See VM lifecycle and hypervisor backends for backend choice and lifecycle behavior.

VM monitor

The VM monitor is the control center for a guest. It prepares guest memory and boot inputs, attaches the requested devices, starts execution, observes exits and device work, and applies stop or restore actions.

The monitor presents a small state view to its callers. A guest is running, quiesced after a held checkpoint, or exited with a status. Events report guest-driven changes such as exit or reset, while the handle keeps the durable VM record that recovery uses.

This diagram shows how a VM request becomes guest execution and how guest activity returns to the monitor.

flowchart LR
    A[VM request] --> B[VM driver]
    B --> C[VM monitor or VMM adapter]
    C --> D[Guest memory and boot state]
    C --> E[Hypervisor backend]
    C --> F[Device model]
    F --> G[Host services]
    E --> H[Guest execution]
    H --> C
    G --> F

The driver contract also supports preparing an external VMM before a guest is ready. Preparation can make the process, private area, and guest-initiated listener available in advance. A later boot consumes that prepared VM once, so a plain boot and a prepare-then-boot path have the same external behavior.

References: virt/…/lib.rs• L11-34 virt/…/driver.rs• L26-101 virt/…/capability.rs• L33-103 virt/…/checks.rs• L285-369 virt/…/fake_prepared.rs• L96-118

Hypervisor backends

The backend decides where vCPUs run and how the host supplies guest memory. Linux uses KVM. macOS can use managed execution through Virtualization.framework or manual execution through Hypervisor.framework. External Firecracker execution adds a process and API boundary around a KVM-backed guest.

The backend exposes only the capabilities it can honor. A capability is an optional operation such as guest vsock, checkpoint, staging, balloon control, console output, or diagnostics. The driver claims the backend-wide feature set, and each VM handle also checks whether that VM requested the related device or service.

Backend shapeGuest execution ownershipRecovery and host boundary
Managed macOS VMMThe platform framework runs the vCPUs and owns part of the device behavior.The driver controls the framework VM through the common contract.
Manual hypervisor monitorThe monitor runs vCPUs and handles exits, memory access, interrupts, and in-tree devices.The monitor joins guest requests to host resources directly.
External Firecracker VMMFirecracker runs as a separate process and exposes a control socket.The driver records the process and its private area so a later process can recover or clean it up.

Firecracker can run directly against host paths or inside a per-VM jail. In jail mode, the VMM sees only staged boot files and disks inside its private root. The driver records the jail path with the process record because a running jailed process does not reliably reveal that path to a later adopter.

When the process that launched an external VMM is lost, recovery first verifies that a live process belongs to the VM. If its control API answers, the driver rebuilds the full handle and reads back VM state and devices. If the API is unavailable, it keeps a process-only handle that can observe and kill the verified process and can still manage its staged area. This preserves safe cleanup without pretending that unavailable devices work.

References: virt/…/driver.rs• L31-90 virt/…/driver.rs• L183-220 virt/…/capability.rs• L318-375 virt/…/driver.rs• L50-100 virt/…/discover.rs• L29-59 virt/…/adopt.rs• L39-86 virt/…/process_only.rs• L31-126

Device model

The device model gives the guest standard virtual hardware instead of direct access to host resources. VirtIO transports guest queue requests through guest memory and interrupts. Device implementations then map those requests to disks, networks, files, sockets, randomness, console output, or memory targets.

The device set is shaped by both the monitor and the selected backend. A managed framework may provide a device itself. A manual monitor registers an in-tree device and connects its transport to the matching host service. The guest-visible contract stays stable even when the host-side path changes.

Device familyGuest viewHost-side purpose
BlockVirtual disksReads and writes image files or block devices.
NetworkVirtual Ethernet interfacesCarries guest packets to a host network path.
FilesystemA mounted shared directoryCarries file operations across the guest-host boundary.
VsockHost-guest socket portsCarries control, readiness, execution, and service traffic without guest IP networking.
Console and serialBoot and operator outputCarries early boot and interactive output.
EntropyRandom data sourceSupplies guest randomness from the host.
BalloonGuest memory targetLets the host ask the guest to release usable pages.

The balloon is an example of a device whose result depends on the host. On Linux, released pages can return to the host through the memory advice path. On macOS, the same current path does not reclaim physical memory, so higher layers keep idle balloon use disabled where reclaim is not available. Block requests also validate guest-provided ranges before host I/O, which keeps malformed requests inside the guest disk boundary.

See VirtIO device stack for transport, queues, and device-specific behavior.

References: virt/…/lib.rs• L16-55 virt/…/lib.rs• L104-180 virt/…/request.rs• L56-150 virt/…/driver.rs• L126-179

Host integration

Host integration makes a virtual device useful while keeping the guest inside its VM boundary. The driver maps guest intent to host paths, host sockets, network attachments, and process controls. Each resource stays tied to the VM lifetime and is released only after guest work no longer uses it.

Guest memory and boot state

Guest RAM is host-backed memory mapped into the guest's physical address space. The monitor uses it for boot data, device queues, and guest I/O. The memory boundary checks addresses and lengths before access so a guest request cannot reach an unmapped host region.

On macOS, the platform can track changed memory in software because Virtualization.framework does not provide KVM-style dirty-page tracking. It records page checksums as a baseline and reports pages whose contents changed. This supports the checkpoint and restore model without changing the common driver contract.

References: virt/…/memory.rs• L62-87 virt/…/memory.rs• L282-429

Private file areas

An external VMM that runs under a jailer receives a private per-VM area. The driver places kernels, root disks, and checkpoint data there before the VMM starts. Read-only data can share storage when safe. Writable disks receive private copies, block devices are represented by device nodes, and handed-over disks move into the area.

The area has two ownership paths. A prepared VM owns cleanup for a process it spawned. An adopted handle owns cleanup when the launching process is gone. A disk that must survive the VM leaves the area before the area is removed. See Guest filesystem sharing for the separate host-directory sharing boundary.

References: virt/…/jail.rs• L23-92 virt/…/jail.rs• L235-274 virt/…/jail.rs• L395-428 virt/…/render.rs• L43-55 virt/…/render.rs• L188-243 virt/…/prepared.rs• L51-115

Guest control channels

Vsock provides direct host-to-guest and guest-to-host channels. The host can dial a guest service. The guest can dial a host listener before or during boot. ArcBox uses this path for readiness, workload execution, file operations, and other control traffic.

The in-VM agent listens on fixed vsock services and reports readiness only after its required listeners are available. It can run commands with piped or terminal I/O, stream output, deliver signals, and report process exit. It also exposes file operations and watches, while the host remains the trusted initiator of those file requests.

The agent keeps guest wall time aligned with the host after startup and after accepted service connections. This matters for restored guests because a snapshot restores the old clock before the first post-restore workload request.

sequenceDiagram
    participant H as Host service
    participant V as Vsock
    participant A as Guest agent
    participant P as Guest workload

    A-->>H: Ready connection
    H->>V: Dial service port
    V->>A: Framed command or file request
    A->>P: Start or access workload
    P-->>A: Output, file result, or exit
    A-->>H: Framed result and status

References: virt/…/driver.rs• L126-161 virt/…/capability.rs• L20-30 virt/…/capability.rs• L213-226 virt/…/main.rs• L1-36 virt/…/main.rs• L503-573 virt/…/main.rs• L788-810

Runtime relationships

Workload orchestration asks the VM driver to create or restore a guest. The driver and monitor build the selected backend, attach devices, and return a handle. The handle then reports state and events while optional capability ports provide only the host services that both the backend and VM configuration support.

The durable record connects runtime control to recovery. It identifies the VM, names its driver and runtime area, and records external process details when needed. A later process can use that record to adopt a surviving VMM or remove the private area left by one that is gone.

This diagram shows the common control relationship from workload orchestration to guest services.

sequenceDiagram
    participant O as Workload orchestrator
    participant D as VM driver
    participant M as VM monitor or adapter
    participant B as Backend
    participant G as Guest
    participant S as Host services

    O->>D: Boot or restore VM request
    D->>M: Validate and prepare request
    M->>B: Create isolated guest
    M->>G: Load boot state and expose devices
    B-->>M: Run guest
    G->>M: Device requests and events
    M->>S: Use controlled host resources
    M-->>O: State and capability results
    O->>D: Shutdown or detach
    D->>M: Stop guest and release resources

The contract tests protect the relationships that are easy to break across backends. They check that lifecycle state and exit events agree, that capability claims match handle accessors, that prepare then boot matches plain boot, that staged files are usable, and that detach then adopt returns the same VM with its needed boundary information.

References: virt/…/driver.rs• L94-180 virt/…/driver.rs• L359-416 virt/…/checks.rs• L31-90 virt/…/checks.rs• L170-225 virt/…/checks.rs• L480-520 virt/…/checks.rs• L770-843 virt/…/fake_prepared.rs• L248-301

Change checklist

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

  • A backend change must keep driver capability claims aligned with the optional handle accessors and with the prepare, boot, restore, detach, and adopt paths.
  • A change to an external VMM record must preserve enough process and jail identity for a later adopter to find the right VM and clean the right private area.
  • A change to staged disk or checkpoint names must keep staging, boot rendering, checkpoint restore, and disk handover on the same names.
  • A new device or changed device capability must update guest discovery, host attachment, queue completion, and the backend's advertised feature set together.
  • A memory or balloon change must keep guest address bounds safe and must distinguish Linux reclaim from macOS memory hints.
  • A vsock service change must preserve listener timing, port direction, framed message compatibility, and cleanup when the VM exits.

Important failure modes

TriggerConsequenceGuard
A backend claims a capability that its handle does not exposeOrchestration reaches an absent or broken service path.Keep DriverCapabilities and handle accessors in agreement.
A jailed VMM is adopted without its recorded jailHost paths and guest sockets point outside the VM area.Rebuild the layout from the durable jail record.
A VMM API is unavailable during adoptionDevice and state operations cannot be restored.Return a process-only handle that can still observe, kill, detach, and manage staging.
A writable disk is hard-linked into a VM areaGuest writes change the caller's source disk.Use a private copy for writable images and preserve device-node handling for block devices.
Guest memory or block ranges exceed their mapped or configured boundsHost memory or disk access can fail or cross its intended boundary.Check address, length, sector, and capacity arithmetic before host access.
A required vsock listener is not bound before guest dial-outBoot readiness or a control connection is missed.Bind prepared listeners before boot and treat VM exit as the end of acceptance.
A restored guest keeps snapshot wall timeWorkload timestamps and certificate checks can be wrong after restore.Sync the guest clock before handling post-restore workload traffic.

Key files

FileWhy to read it
virt/…/lib.rsDefines the platform-neutral VM vocabulary and the boundary between orchestration and adapters.
virt/…/driver.rsShows the common driver, handle, state, record, and capability model.
virt/…/capability.rsExplains optional services, preparation, staging, checkpointing, adoption, and vsock direction.
virt/…/checks.rsShows the cross-backend behavior the contract requires.
virt/…/driver.rsShows how an external Firecracker backend maps the common contract to boot, restore, adopt, and cleanup.
virt/…/render.rsShows the relationship between VM intent, host paths, and jailed VMM paths.
virt/…/jail.rsShows the private-area boundary and the resource staging model.
virt/…/adopt.rsShows how a surviving external VMM is identified and rebuilt after host process loss.
virt/…/memory.rsShows the macOS guest-memory boundary and software dirty tracking used for snapshots.
virt/…/lib.rsShows host memory target behavior and the platform difference in page reclaim.
virt/…/request.rsShows the guest block request boundary and checked disk-range rules.
virt/…/main.rsShows the guest-side vsock services for readiness, workload control, file operations, and clock sync.