Container and OCI runtime
ArcBox runs container workloads in one Linux System VM. The host daemon presents a Docker-compatible control surface, the guest agent prepares and starts the container runtime, and the guest runtime creates the workload process and its filesystem. Engine-managed VM state and runtime readiness remain separate so a running VM is not treated as a ready container service.
Runtime purpose
The container runtime provides the execution layer for Linux workloads. It brings up containerd and dockerd inside the System VM, then uses their normal container and image services to materialize root filesystems, start processes, and report workload state. The host keeps the Docker-facing control path while the guest owns process execution.
The runtime uses one System VM rather than a separate VM for each container. Native arm64 workloads run directly in that guest. linux/amd64 workloads use FEX through the guest's binfmt_misc support, and ArcBox rejects such work when that translator is not available instead of selecting another VM.
References: app/…/routing.rs• L1-13 app/…/routing.rs• L64-123
Runtime materialization
Runtime materialization turns a verified boot asset generation into an executable guest-local runtime. The agent selects the current architecture, checks the generation manifest and asset digests, copies the required executables to persistent storage, and publishes one stable path for the runtime services. A complete generation can be reused after a guest restart.
The materialization step is separate from container image materialization. It installs the programs that run containers. containerd and dockerd then use their own image and snapshot stores to provide each container's filesystem.
flowchart LR
Manifest[Verified runtime manifest] --> Select[Select guest architecture]
Assets[Boot runtime assets] --> Verify[Copy and verify assets]
Select --> Verify
Verify --> Generation[Publish immutable runtime generation]
Generation --> Stable[Stable guest runtime path]
Stable --> Services[containerd and dockerd]
Services --> Workload[Container workload]
The stable path changes as a whole when a new generation is published. Failed or incomplete copies do not become the active runtime, which keeps a previous working generation available until the replacement is complete.
References: guest/…/runtime_materialize.rs• L22-46 guest/…/runtime_materialize.rs• L75-131
Runtime startup
Runtime startup prepares the guest before it starts container services. The agent makes the required kernel and writable filesystem facilities available, materializes the local runtime, starts containerd, and starts dockerd against the guest data store. It reports readiness only after the Docker API answers /_ping.
The startup sequence has distinct service meanings:
- A reachable containerd socket means containerd can accept connections.
- A reachable dockerd socket means dockerd has opened its endpoint.
- A successful Docker
/_pingmeans the engine has completed enough initialization to accept Docker work.
The host asks the agent to ensure this runtime without holding the request open for the full cold-start period. One caller starts the work in the background. Other callers receive an in-progress result, and later calls receive the cached ready or failed result. A failed attempt can be retried by a later ensure request.
References: guest/…/ensure_runtime.rs• L39-50 guest/…/ensure_runtime.rs• L86-101
sequenceDiagram
participant Host as Host engine
participant Agent as Guest agent
participant Runtime as containerd and dockerd
participant API as Docker API
Host->>Agent: Ensure runtime
Agent-->>Host: Starting
Agent->>Agent: Prepare guest prerequisites
Agent->>Runtime: Start containerd
Runtime-->>Agent: containerd socket ready
Agent->>Runtime: Start dockerd
Runtime->>API: Open socket and load state
Agent->>API: Probe /_ping
API-->>Agent: Ready
Agent-->>Host: Ready and endpoint
Host->>Agent: Poll or use Docker endpoint
The host engine starts the System VM first, then waits for the guest container runtime. This ordering makes VM readiness distinct from Docker readiness: a VM process can exist, and the guest agent can answer, while dockerd is still loading its state.
References: app/…/runtime.rs• L861-927 guest/…/runtime.rs• L56-75 guest/…/runtime.rs• L96-137
Workload lifecycle
Container lifecycle requests enter through the Docker-compatible host API and are proxied to dockerd in the System VM. The host adds the work that depends on the container's guest state, such as setting up host port forwarding and DNS after a successful start. Stop, kill, restart, and remove requests update or remove that host-side state after the guest operation succeeds.
flowchart LR
Request[Docker container request] --> Host[Host Docker layer]
Host --> Ready[Ensure System VM and runtime readiness]
Ready --> Proxy[Proxy request to guest dockerd]
Proxy --> Engine[containerd and dockerd]
Engine --> Process[Create or control workload process]
Process --> Inspect[Inspect guest state]
Inspect --> HostState[Update host DNS and port forwarding]
Container creation carries the workload contract. It includes the image, command, environment, working directory, mounts, resource limits, ports, labels, and restart policy. The Docker-compatible API sends this contract to guest dockerd, which creates and starts the container.
The arcbox-container crate provides a host-side domain model for this contract. It is not the live container manager today. The current execution path is the Docker API proxy, guest dockerd, and containerd.
References: runtime/…/config.rs• L21-54 rpc/…/container.proto• L67-99 runtime/AGENTS.md• L15-25
The host records the canonical full container ID and name after a successful start. Later lifecycle calls can use a name, a short ID, or the full ID while host networking remains keyed by the canonical ID. A periodic reconciler checks the guest's running set so natural exits, OOM kills, auto-removal, and direct guest operations do not leave stale host forwarding or DNS entries.
References: app/…/mod.rs• L78-109 app/…/mod.rs• L288-324 app/…/host_reconciler.rs• L1-11
OCI workload model
The OCI model describes the inputs and state that a low-level container runtime needs. An OCI bundle is a directory with config.json and a root filesystem. The configuration defines the process, root, mounts, Linux isolation settings, and related limits. The bundle layer resolves the root filesystem and validates the bundle before a runtime can use it.
References: runtime/…/bundle.rs• L1-7 runtime/…/bundle.rs• L36-73
The OCI state model records the container ID, bundle path, process ID, annotations, timestamps, root filesystem, and exit code. Its status moves through creating, created, running, and stopped. The state store persists this record by container ID so a runtime can recover the last known lifecycle state.
| OCI state | Meaning | Next normal state |
|---|---|---|
creating | The runtime is preparing the bundle and process environment. | created |
created | The container exists but its init process has not started. | running |
running | The container init process has a guest PID. | stopped |
stopped | The process ended and the state carries its exit result. | None |
Creation can move directly to stopped when setup fails. This gives failure handling a terminal state instead of leaving a partially created workload looking active.
References: runtime/…/state.rs• L15-40 runtime/…/state.rs• L91-105 runtime/…/state.rs• L109-185
Engine lifecycle relationship
Engine-managed lifecycle state describes the System VM and the availability of its guest services. OCI or Docker container state describes an individual workload inside that VM. The engine must therefore establish readiness in layers rather than map one state into the other.
| Layer | What it proves | What it does not prove |
|---|---|---|
| VM process running | The System VM process exists. | The guest agent or Docker engine is ready. |
| Guest agent ready | The host can exchange control requests with the guest. | dockerd has finished loading containers. |
| Docker runtime ready | dockerd answers /_ping and can accept Docker work. | A specific container is running. |
| Container running | The workload process is active in the guest. | The System VM will remain available. |
The runtime manager uses the System VM lifecycle to start or stop the shared guest. A VM restart stops running containers, but the persistent Docker data image preserves container and image records for the next boot. The Docker proxy uses a restart generation to discard stale connections on the next request, while consumers that need the VM coming up watch the VM lifecycle state itself.
References: app/…/runtime.rs• L518-531 app/…/runtime.rs• L578-593
This separation also explains why a successful VM readiness check is not enough for a container request. The host must wait for the guest runtime's API readiness before it proxies Docker work, and the guest runtime must still report the individual container result after that point. The related guest-agent control path is described in Guest agent integration.
References: app/…/runtime.rs• L460-471 guest/…/runtime.rs• L372-456
Exec workload flow
Exec creates a second process inside an existing running container. The host-side exec model keeps the command, environment, working directory, user, TTY, attach mode, and container ID. With a live agent connection, the manager sends these parameters to the guest and tracks the returned PID, output, and exit code.
The exec path supports attached and detached work. Attached work returns output and a completion result when the guest process ends. Detached work returns after the guest starts the process, and a later exit notification completes the local exec record. TTY resize is valid only while a TTY-backed exec is running.
References: runtime/…/exec.rs• L41-64 runtime/…/exec.rs• L115-163 runtime/…/exec.rs• L221-323
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the three readiness meanings aligned: VM lifecycle readiness, guest runtime readiness, and Docker
/_pingreadiness. A change to one timeout or probe can make the host accept work too early or report a healthy VM as an unusable runtime. - When changing the runtime manifest or asset path, keep manifest generation, digest verification, stable-link publication, architecture selection, and FEX registration aligned. A new generation must not publish until every required executable is verified.
- When changing Docker container lifecycle handling, keep canonical ID resolution, host port forwarding, DNS registration, immediate teardown, and periodic reconciliation aligned. A new lifecycle result can otherwise leave host state for a stopped guest workload.
- When mapping container state between Docker and OCI surfaces, preserve their different state vocabularies. Docker-facing state includes paused, restarting, removing, and dead; OCI state has a smaller validated lifecycle.
- When changing containerd snapshot behavior, keep the guest snapshot lookup and the host filesystem consumer aligned with the containerd namespace, snapshotter, and mount shape.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Dockerd socket opens while its API is still loading state | The host can report readiness and send requests that fail during startup | Use Docker /_ping as the ready gate, not socket reachability alone. |
| Runtime asset digest or generation does not match the manifest | The guest cannot safely publish the requested runtime generation | Verify the manifest version and each asset digest before publication. |
| FEX is missing for a linux/amd64 workload | The workload cannot execute correctly in the shared guest | Fail closed during container creation instead of falling back to another VM or translator. |
| A container exits without a matching host API call | Port forwarding, DNS, or name aliases can remain stale | Reconcile registered host state against the guest's running container IDs. |
| A guest status query fails during reconciliation | Live host networking could be removed by mistake | Skip teardown for that cycle and retry later. |
| A lifecycle request uses a name or short ID after the container's host state was registered by full ID | Teardown can miss the host networking record | Resolve the request token to the canonical full container ID before teardown. |
| A workload setup error leaves OCI state before a terminal transition | The workload can appear stuck in creation | Allow creation failure to transition directly to stopped. |
Key files
| File | Why to read it |
|---|---|
| app/…/runtime.rs | Shows how the engine starts the System VM, waits for the guest runtime, and distinguishes VM lifecycle state from Docker readiness. |
| app/…/mod.rs | Shows the host lifecycle boundary for create, start, stop, kill, restart, and remove operations. |
| app/…/routing.rs | Shows the single-VM execution model and the native-versus-FEX workload decision. |
| app/…/host_reconciler.rs | Shows the backstop that removes host networking state after unobserved guest exits. |
| guest/…/runtime.rs | Shows guest runtime startup, service probes, and Docker API readiness. |
| guest/…/ensure_runtime.rs | Shows the non-blocking ensure state machine and cached runtime readiness result. |
| guest/…/runtime_materialize.rs | Shows verified, atomic publication of the guest-local runtime generation. |
| runtime/…/bundle.rs | Shows the OCI bundle as the configuration and root filesystem input to a runtime. |
| runtime/…/state.rs | Shows OCI lifecycle state, persistence, and valid transitions. |
| runtime/…/exec.rs | Shows the host-to-guest model for commands run inside an existing container. |
| rpc/…/container.proto | Shows the public container lifecycle and exec contract. |