Workload engine
ArcBox turns desired container, computer, or sandbox state into a usable runtime. It selects the owning VM and guest service, prepares trusted boot and storage inputs, tracks each physical VM run, and reports readiness only when the workload can accept work.
Workload model
ArcBox uses one workload model across two runtime shapes. Container work uses a shared System VM. Computers and sandboxes use guest environments with their own VM or guest-service boundary.
Container workloads
A container workload describes an image and process settings such as commands, environment, mounts, limits, ports, and network mode. The host makes the System VM and its guest endpoint ready. The guest container service then owns image layers, processes, logs, and container state.
The System VM is a shared platform, not part of each container's visible state. VM readiness and container readiness are therefore separate conditions.
References: engine/…/machine.rs• L24-40 engine/…/agent_client.rs• L599-733 engine/…/boot.rs• L436-521
Computer workloads
A computer is a named Linux environment backed by one VM record. Its desired state includes compute size, boot inputs, block devices, shared host directories, network identity, and optional distribution data. The record remains across stop and restart, while the guest address belongs only to the physical run that produced it.
This split lets the engine rebuild a computer without allowing a late result from an old VM run to change the replacement run. Backend and resource choices apply to the next start when the current run cannot change them safely.
References: engine/…/machine.rs• L66-115 engine/…/machine.rs• L632-804 engine/…/vm.rs• L120-180
Sandbox workloads
A sandbox is a guest workload managed inside the System VM. Its guest agent handles sandbox actions such as create, run, file access, pause, resume, checkpoint, restore, and removal. The engine provides the agent connection and VM boundary.
The Computer runtime composition page explains that host boundary. The Images and snapshots page explains the artifacts used for repeatable boot and restore.
References: engine/…/agent_client.rs• L1246-1408 engine/…/agent_client.rs• L1457-1844 engine/…/agent_client.rs• L1847-1989
Runtime roles
The engine separates named workload records from physical VM runs and guest work. The machine manager owns workload records. The VM manager owns physical VM entries. The guest agent provides the control link inside a VM. The lifecycle actor coordinates boot, readiness, idle state, stop, and recovery without blocking command handling.
The Engine orchestration page describes how these roles work together.
References: engine/…/machine.rs• L437-463 engine/…/vm.rs• L25-45 engine/…/actor.rs• L338-379
Desired-state translation
The engine treats a workload request as desired state and assembles the resources needed to make that state true. It resolves policy and boot inputs, creates or reuses a VM record, starts one physical run, waits for guest readiness, and publishes usable state.
Runtime assembly
The shared translation path moves from a request to a workload-ready runtime:
- A caller supplies a container, computer, or sandbox request.
- The engine selects the owning runtime and applies its defaults.
- It resolves the boot image, root filesystem, kernel, storage, network policy, and host backend.
- It creates or reuses a VM record and starts a physical run.
- It admits a compatible guest-agent connection.
- It waits for the readiness condition owned by that runtime.
- It starts or exposes the workload and publishes lifecycle state.
The diagram shows where container work stays in the System VM and where computer work becomes VM operations.
flowchart TD
Request[Desired workload state] --> Model[Workload model and defaults]
Model --> Kind{Workload type}
Kind -->|Container| System[System VM]
Kind -->|Computer| Machine[Named computer VM]
Kind -->|Sandbox| Guest[Sandbox guest service]
System --> Agent[Guest agent and runtime readiness]
Machine --> Agent
Guest --> Agent
Model --> Assets[Trusted boot and storage inputs]
Assets --> VM[Physical VM run]
VM --> Agent
Agent --> Ready[Workload-ready state]
Ready --> Events[State and lifecycle events]
References: engine/…/boot.rs• L222-291 engine/…/machine.rs• L825-1014 engine/…/vm.rs• L251-312
Container translation
Container requests use the guest container service instead of host-side image and process operations. The engine makes the System VM ready and sends the request through the agent. The guest service then manages container images, layers, processes, logs, and state.
A container image is not a machine boot image. The former belongs to the guest container service. The latter supplies a root filesystem that a VM can boot.
References: engine/…/agent_client.rs• L1054-1139 engine/…/agent_client.rs• L599-733 engine/…/boot.rs• L436-521
Computer translation
Computer creation combines hardware, boot, image, mount, and network choices into a persistent record and VM configuration. A distribution-backed computer uses a read-only root filesystem with a writable data disk. A plain VM keeps the caller's kernel and block-device choices.
Starting a computer creates a new physical run identity. The engine checks protocol compatibility and guest usability before it saves addresses or publishes the start event. Backend and resource size changes apply only while the computer is stopped, so the next run uses one stable configuration.
References: engine/…/machine.rs• L129-215 engine/…/machine.rs• L632-804 engine/…/machine.rs• L825-1014 engine/…/vm.rs• L120-312
Guest-agent translation
The guest agent is the control interface for readiness and guest work. Each business request first admits a compatible protocol version. A missing handshake or an older protocol fails before guest work starts.
Long-running watches and retained sessions use dedicated connections. Cancellation closes the connection and joins its worker before the owner retires the VM. Instance authority sessions also require each replacement acknowledgement to carry the requested source revision. This keeps host and guest authority state aligned and prevents guest work from outliving its runtime.
References: engine/…/agent_client.rs• L89-129 engine/…/instance_authority.rs• L25-140 engine/…/retained_session.rs• L18-116 engine/…/tests.rs• L80-135
Artifact and resource model
Workloads use separate artifacts for boot, writable state, and recovery. This lets a machine reuse a trusted root filesystem while keeping its own data and identity.
Image sources
The image layer resolves a distribution and architecture through a published index. It then resolves an immutable manifest and downloads the root filesystem into staging. The image becomes visible locally only after its size and SHA-256 digest match the manifest.
Pulls for one image stream are serialized. A cancelled pull waits for pending writes before staging is removed, so a retry cannot inherit a partial image. See Images and snapshots for the wider image and checkpoint lifecycle.
References: engine/…/machine_image.rs• L62-184 engine/…/machine_image.rs• L186-347 engine/…/machine_image.rs• L349-529 engine/…/error.rs• L9-32
QEMU runtime assets
When the System VM needs emulation, the image layer supplies a QEMU build as a managed runtime asset. The selected build comes from the pinned asset record or a development override. ArcBox downloads it only when needed and publishes it only after the archive, layout, licenses, and code signatures pass their checks.
The runtime keeps incomplete downloads for later resume and uses one install lock for competing users. A complete checked build is moved into place as one unit, so the VM either sees a valid build or no build. This keeps a host fallback separate from the guest boot image and workload data.
References: engine/…/mod.rs• L1-9 engine/…/mod.rs• L37-95 engine/…/download.rs• L13-31 engine/…/download.rs• L49-89 engine/…/install.rs• L46-106 engine/…/signature.rs• L15-25
Storage views
The engine treats a shared read-only boot image and writable workload state as different resources. A computer owns a writable data disk. The System VM uses a persistent sparse data image with a paired metadata image. Its logical size can grow, but an existing image is never shrunk.
Clones and exports operate on stopped distribution machines because the data disk must represent stable guest state. A clone gets a new identity and its own data-disk view. An archive records the source image manifest and written disk extents without embedding the shared root filesystem.
References: engine/…/vm.rs• L1123-1192 engine/…/clone.rs• L1-15 engine/…/clone.rs• L29-158 engine/…/mod.rs• L1-74 engine/…/transfer.rs• L30-95
Snapshot lineage
A VM snapshot records a restorable point for one VM. The VM manager captures and applies that state only for the matching VM. The guest agent also exposes sandbox checkpoints, snapshot listing, restore, and template catalog actions.
Snapshots and templates are workload artifacts. They do not replace the machine record. The Images and snapshots page covers ownership, version selection, and restore rules.
References: engine/…/vm.rs• L646-820 engine/…/agent_client.rs• L1847-1989
Lifecycle coordination
The engine coordinates physical VM state, guest readiness, durable records, and public events. Each layer reports only the condition it owns, so a VM process, an answering agent, and a usable workload are not treated as the same state.
Readiness states
System VM readiness moves through creation, start, protocol admission, guest readiness, and runtime readiness. The lifecycle state is Running only when the agent can accept work. An idle VM remains usable while its lifecycle state records reduced recent activity.
A single lifecycle actor owns state transitions. Slow boot and stop work runs outside the actor and returns an epoch-tagged result. This lets force stop preempt older work without allowing a late completion to change the newer lifecycle state.
A distribution computer adds guest usability to agent reachability. The agent can answer before distribution init and network setup finish. The engine waits for settled guest state and a routable address before it publishes the computer as ready.
References: engine/…/actor.rs• L1-13 engine/…/actor.rs• L78-106 engine/…/boot.rs• L659-859 engine/…/machine.rs• L936-1014
State persistence
Machine records preserve the configuration needed to rebuild a VM after a process restart. A record last saved as running loads as stopped because its old physical VM no longer exists. The engine marks that record as recovered before a new operation can claim the same identity.
The persistence manager serializes updates so address and policy changes do not overwrite one another with stale records. Lifecycle events provide the live view for consumers.
References: engine/…/persistence.rs• L15-168 engine/…/persistence.rs• L195-323 engine/…/event.rs• L5-56
Run identity
An incarnation is the identity of one physical start or reboot of a VM entry. The engine passes it through agent connections, address publication, listener transfer, stop, and removal.
This fence prevents an old operation from changing a replacement run. A stopped or created VM also has an incarnation, but that identity proves only which record the operation targets. It does not prove that the VM is live.
References: engine/…/incarnation.rs• L5-154 engine/…/machine.rs• L1193-1272 engine/…/vm.rs• L314-348
Stop ownership
One stop operation owns each physical run. A graceful stop can hand the same run to a forced stop after its deadline. Concurrent callers share the result instead of starting competing teardown actions.
Before teardown, the engine publishes a stopping boundary and waits for host holds to drain. A hold represents host work that still depends on the guest, such as a mounted guest export. If the deadline expires, the engine fails before touching the VM.
References: engine/…/stop_owner.rs• L5-185 engine/…/host_hold.rs• L1-89 engine/…/machine.rs• L1553-1608
Guest sessions
Some guest services need a connection that lives longer than one request. Machine web policy and instance authority sessions fix guest identity when they open, serialize replacements, and require the matching revision in each acknowledgement. Guest trust and web-service observation use dedicated cancellable requests.
The session owner must observe connection failure and join the coordinator before releasing the machine hold or stopping the VM. An acknowledgement confirms that the guest received the policy. It does not prove that host routes are installed.
References: engine/…/machine_web.rs• L25-147 engine/…/instance_authority.rs• L25-140 engine/…/guest_trust.rs• L14-64 engine/…/web_services.rs• L14-83
Recovery and release
Every lifecycle path has a matching release path for the VM, guest connections, network identity, writable disk state, and durable record. Stop releases live runtime resources while keeping a machine record. Remove also deletes the VM record and owned machine artifacts.
Storage maintenance reserves the System VM before stopping it. The lifecycle actor keeps recovery boot and storage stop in one ordered flow. The reservation blocks normal VM changes, cancels and joins recovery boot, and keeps a durable protection hold after a storage failure. Guest-agent checks report results, but the recovery owner decides when the storage hold is safe to remove. See Storage recovery for that flow.
References: engine/…/actor.rs• L40-55 engine/…/actor.rs• L614-645 engine/…/boot.rs• L29-129 engine/…/boot.rs• L412-435 engine/…/README.md• L31-55
Composition boundary
The workload engine stays reusable by keeping host-specific choices at composition boundaries. The host supplies the VM backend, host network, route hooks, and storage policy. The engine supplies workload state, VM lifecycle, image selection, guest-agent access, persistence, and events.
Host and guest boundary
The host owns the physical VM and its network attachment. The guest owns container services, sandbox actions, guest exports, and guest web state. A versioned agent wire contract connects these sides with trace information and structured errors.
This boundary lets the same workload model use the guest transport required by each VM backend. It also lets host cleanup stop admissions and interrupt guest I/O before VM teardown.
References: engine/…/types.rs• L75-172 engine/…/wire.rs• L7-77 engine/…/machine.rs• L1239-1272 engine/…/types.rs• L83-120
Workload-facing policy
Some settings describe desired policy rather than an action taken at once. Machine web settings persist HTTP and HTTPS backend choices as Auto, Off, or an explicit port. Omitted updates keep the saved value. Saving policy does not install routes; a later host or guest service consumes it.
Machine identity also crosses this boundary. Names map to hostnames and are reserved before registration. Clones and imports preserve workload settings while assigning a new name, hostname, VM identity, and data-disk ownership.
References: engine/…/web_ports.rs• L16-115 engine/…/wire.rs• L7-55 engine/…/machine.rs• L354-410 engine/…/transfer.rs• L73-112
Change checklist
When these files or sections are changed, remember to consider these:
- Keep physical run identity checks with every operation that connects to, publishes state for, transfers listeners from, or stops a VM.
- Keep guest protocol admission and readiness aligned with the agent wire contract. A new request must work through both async and blocking transports when both are supported.
- Keep cancellation paired with worker joins before releasing host holds or retiring a VM. Dropping a future alone does not prove that guest I/O ended.
- Keep instance authority sessions exclusive and revision-checked. A session must observe idle failure and join its coordinator before reconnection or VM retirement.
- Keep machine persistence fields aligned with create, clone, archive, import, and restart recovery. A field that is not copied or reloaded can silently change the next boot.
- Keep rootfs, data-disk, metadata-volume, and kernel device order aligned with the guest boot contract.
- Keep image landing atomic. A verified manifest and rootfs must become visible together, and a cancelled pull must not leave a reusable partial entry.
- Keep QEMU selection, archive digest, build metadata, signature policy, and published install marker aligned. A development override must not change production pin behavior.
- Keep graceful and forced stop ownership on one captured VM incarnation. Do not reacquire a VM by name after an asynchronous stop path begins.
- Keep lifecycle completion epochs aligned with spawned boot, reboot, stop, and removal work. An aborted task may still have queued a stale result.
- Keep storage recovery reservations and durable protection holds distinct. Releasing the in-memory reservation must not release protection after a failed check.
- Keep web and authority session revisions strictly increasing and validate the exact acknowledgement before reporting policy as applied.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The VM is running but the agent has not completed a compatible handshake | Guest work is rejected or waits while the VM looks active | Admit the protocol before business requests and fail old or incompatible agents early |
| The agent answers before distribution init and network setup finish | A computer is reported ready while guest services or routes still fail | Wait for settled guest init and a routable address |
| A late address or readiness result belongs to an earlier physical run | A replacement VM receives stale state or an old start event | Carry and validate the expected VmIncarnation before publication |
| A late boot or stop completion belongs to an aborted lifecycle task | A force stop or replacement run can be moved back to an old state | Tag sub-task results with the current lifecycle epoch and drop stale results |
| A host export or session still holds a machine during stop | Teardown breaks host work or leaves an unusable mount | Publish the stopping boundary and wait for host holds, with a bounded failure before teardown |
| A cancelled blocking RPC keeps its worker or socket alive | VM removal races with guest I/O | Close the dedicated socket and await the worker or retained-session coordinator |
| A retained authority session receives an unsolicited, malformed, or wrong-revision frame | Host and guest authority state diverge and the session closes | Require the expected response type and exact authority revision; treat peer EOF as session failure |
| A pinned or resumed QEMU archive fails digest, layout, or signature checks | An unusable or untrusted emulator cannot be published | Verify the archive and extracted build before atomic installation |
| A machine data disk is cloned or exported while running | The result can miss guest writes and is not a stable workload image | Require a created or stopped distribution machine |
| Storage preparation fails and protection is released immediately | Later normal boot can write to damaged storage | Keep the durable recovery hold until verification and write checks succeed |
| A web or authority acknowledgement has the wrong revision | Host and guest policy views diverge | Require the exact requested revision and reject non-increasing source revisions |
Key files
| File | Why to read it |
|---|---|
| engine/…/lib.rs | Defines the daemon-free engine boundary and the platform seams used by its composing layer. |
| engine/…/error.rs | Shows how VM, guest, transport, network, image, and platform failures cross the engine boundary. |
| engine/…/README.md | States the public rules for run identity, stop ownership, storage maintenance, and agent cancellation. |
| engine/…/machine.rs | Shows how named desired machine state becomes a persistent VM-backed environment and how readiness addresses are published. |
| engine/…/vm.rs | Shows the VM resource boundary and the operations for start, stop, snapshot, restore, and removal. |
| engine/…/incarnation.rs | Shows how one physical VM run is fenced from later runs. |
| engine/…/mod.rs | Shows the public lifecycle contract for transparent System VM use, readiness, idle activity, and recovery. |
| engine/…/actor.rs | Shows how one actor owns lifecycle transitions and rejects stale boot or stop completions. |
| engine/…/boot.rs | Shows System VM boot, drift handling, guest readiness, storage preparation, backend choice, and recovery retries. |
| engine/…/actor.rs | Shows how storage reservations and recovery commands are ordered with normal lifecycle work. |
| engine/…/agent_client.rs | Shows the guest-agent contract for readiness, containers, sandboxes, files, executions, snapshots, and templates. |
| engine/…/cancellation.rs | Shows how cancellable guest work ends before its VM owner is retired. |
| engine/…/retained_session.rs | Shows the lifetime rules for long-lived guest sessions and transport workers. |
| engine/…/instance_authority.rs | Shows exclusive guest authority replacement, revision checks, and coordinator ownership. |
| engine/…/tests.rs | Shows that authority sessions handle cancellation, timeout, EOF, malformed responses, and worker joins across supported transports. |
| engine/…/machine_image.rs | Shows image selection, manifest validation, digest checks, cancellation, and atomic local landing. |
| engine/…/mod.rs | Shows how a pinned or development QEMU runtime is selected and exposed to the System VM composer. |
| engine/…/download.rs | Shows resumable QEMU download, retry, cancellation, and progress behavior. |
| engine/…/install.rs | Shows archive checks, staged publication, cleanup, and the single-version install rule. |
| engine/…/signature.rs | Shows the trust rules for production and development QEMU builds. |
| engine/…/tests.rs | Shows the guarantees for pin selection, resumable transfer, failed validation, and atomic install. |
| engine/…/persistence.rs | Shows how machine configuration and interrupted running state survive process restart. |
| engine/…/clone.rs | Shows stopped-machine clone semantics and new workload identity. |
| engine/…/mod.rs | Shows the archive contract for machine settings, image identity, and sparse data state. |
| engine/…/transfer.rs | Shows export and import as stable data-disk transfer around the machine registry. |
| engine/…/stop_owner.rs | Shows shared graceful and forced stop ownership. |
| engine/…/host_hold.rs | Shows why host dependencies must drain before VM teardown. |