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 / guest-agent-integration

Guest agent integration

The guest-resident agent is the control bridge between the host daemon and services inside a guest VM. It prepares guest state, serves host control requests, reports readiness, and coordinates nested sandbox VMs. The host still owns VM creation and teardown; the agent owns work that needs guest-local access.

System boundary

The agent runs as a guest service and listens for host requests over a framed vsock protocol. It turns those requests into guest operations or status events, while the host uses the results to expose runtimes and services to users.

This diagram shows the control path from the host to guest services and then to nested workload VMs.

flowchart LR
    H[Host daemon] -->|vsock control requests| A[Guest agent]
    V[Host VM services] -->|VM lifecycle| S[System VM]
    A --> R[Container and Kubernetes services]
    A --> G[Guest DNS and data services]
    A --> N[Nested sandbox runtime]
    N --> M[Nested VM agent]
    M --> W[Workload process and files]

Guest control plane

The control plane gives the host one guest-facing contract instead of a separate host concern for each guest socket or process. Its broad responsibilities are:

  • Report liveness, system information, readiness, memory pressure, and machine statistics.
  • Start and inspect container and Kubernetes services.
  • Manage guest shutdown, storage trim, filesystem paths, and NFS exports.
  • Coordinate sandbox lifecycle, execution, file access, events, and port forwarding.
  • Reconcile guest web access, trust, and instance authority.

References: guest/…/rpc.rs• L44-116 guest/…/rpc.rs• L206-318

VM service boundary

The host VM layer creates, boots, pauses, restores, and removes the System VM. The agent starts services only after the guest is running and changes state that requires guest privileges. This keeps VM lifecycle decisions outside the guest control service.

Sandbox work crosses a second boundary. The System VM agent passes work to the nested runtime, which controls each nested VM through its own guest-agent connection.

References: guest/…/main.rs• L271-379 guest/…/sandbox.rs• L96-165

Host coordination

The host treats the agent as a readiness and control point. A live connection proves that the agent can answer, but it does not prove that a requested guest service can accept work.

Readiness signals

The agent separates liveness from service readiness so the host can make the right decision at each stage. A ping confirms the control path. A readiness stream reports progress. Runtime-specific checks confirm that the service API is usable.

The host therefore receives different signals for different actions:

  • A ping confirms that the agent answers.
  • A protocol check confirms that the host and guest share a usable contract.
  • A runtime readiness event confirms that the container API is ready.
  • A status response explains partial or failed startup.
  • Resource streams let the host react to guest pressure without repeated polling.

References: guest/…/rpc.rs• L221-318 guest/…/main.rs• L284-359

RPC request handling

The agent receives length-prefixed frames with a message type, trace identity, and encoded payload. It decodes the request, routes it to the guest operation, and returns a typed response or a stream of events. Streaming calls keep the connection open until the watch ends or the caller closes it.

Sandbox messages use the sandbox service's frame dispatcher rather than the general request envelope. The agent checks guest prerequisites before dispatch so an unavailable nested runtime produces a clear service error.

References: guest/…/rpc.rs• L1-7 guest/…/rpc.rs• L196-318 guest/…/sandbox.rs• L59-119

Guest operations

The agent performs operations from inside the guest because mounts, interfaces, process state, service sockets, and guest routing are not safely managed through the host VM boundary alone.

Startup modes

The agent has separate one-shot and serving roles. System initialization prepares the guest before service handling. Distro-machine initialization brings up the machine network and leaves the rest of startup to the distro's init system. The long-running serve mode listens for host requests and starts the services that belong to that guest.

Critical writable mounts are checked after System VM initialization. This prevents the agent from answering while later writes would fail against a read-only guest image.

References: guest/…/main.rs• L106-139 guest/…/main.rs• L239-291

Guest service coordination

In the System VM, the agent starts and joins the guest services that make host features usable. These include guest DNS, container-domain routing, Docker event handling, NFS and SSH relays, and the sandbox service. The service set is selected by guest type, so a distro machine serves its RPC role without starting System VM-only services.

The agent also maintains guest-local state as services change. For example, container events update DNS and routing, while sandbox operations update guest forwarding state.

References: guest/…/main.rs• L284-359 guest/…/mod.rs• L1-30

Nested sandbox operations

The sandbox service exposes nested VM work through the guest agent. It uses the System VM's container images and DNS, then runs workloads in Firecracker microVMs inside the System VM. Each nested VM has its own guest agent for process and file operations.

The guest checks nested virtualization and its persistent data mount before it accepts sandbox work. If those prerequisites are missing, the host receives an explicit failure instead of an opaque nested boot error.

References: guest/…/sandbox.rs• L18-57 guest/…/sandbox.rs• L33-57 guest/…/sandbox.rs• L140-165

Sandbox port forwarding

Sandbox port forwarding connects a host listener to a workload port through the guest. The agent allocates a guest relay port and installs guest forwarding state for TCP or UDP. The mapping is tied to the sandbox generation so stale state cannot be applied to a later sandbox that reuses an address.

Cleanup is durable across agent restarts. The agent removes forwarding state when the host finishes the sandbox cleanup ticket and can sweep tagged orphan rules left by an earlier process.

References: guest/…/port_forward.rs• L1-27 guest/…/port_forward.rs• L90-179 guest/…/port_forward.rs• L463-517

Platform behavior

The agent's full behavior is Linux-specific because its guest work needs Linux mounts, networking, vsock, and service controls. Other builds keep shared code usable but do not provide the Linux guest service.

Linux guest behavior

The Linux agent listens on the guest control port and performs the complete guest operation set. It can prepare the System VM, coordinate container and Kubernetes services, expose guest data paths, and manage nested sandboxes.

The Linux dependency boundary includes the nested runtime, VM driver, TAP network, and vsock support. These capabilities are composed only for Linux guest builds.

References: guest/…/mod.rs• L1-30 guest/…/Cargo.toml• L60-75

Non-Linux development behavior

Non-Linux builds use a stub agent because guest vsock and Linux service operations are not available on the development host. The stub supports shared builds and tests, but it does not prove that guest initialization, runtime startup, or nested VM work succeeds.

Guest behavior must therefore be validated with a Linux guest build and a VM-level path.

References: guest/…/Cargo.toml• L90-92 guest/…/mod.rs• L1-5

Change checklist

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

  • A new host action must stay aligned across the wire schema, message type, guest dispatch, and host caller.
  • Readiness changes must preserve the difference between agent liveness and service API readiness.
  • Startup changes must cover both System VM initialization and distro-machine initialization.
  • Sandbox changes must preserve both the System VM agent boundary and the nested VM agent boundary.
  • Port-forward changes must preserve generation-aware cleanup and orphan-rule recovery.
  • Linux-only dependencies must not be treated as evidence that the non-Linux stub provides guest behavior.

Important failure modes

TriggerConsequenceGuard
The host and guest use different meanings for a control messageThe request is rejected or appears as an unavailable guest serviceKeep schema, message routing, and callers in lockstep
The agent starts before required writable guest state existsLater service setup fails during a guest writeVerify critical mounts before serving
Nested virtualization or sandbox data state is missingSandbox creation fails before a workload VM startsProbe prerequisites before accepting sandbox work
A sandbox generation ends before its forwarding rules are removedA later sandbox can receive stale trafficTie rules to cleanup tokens and sweep tagged orphans
A non-Linux build is used to validate guest behaviorShared code passes while the Linux service is untestedValidate a Linux guest image through a VM path

Key files

FileWhy to read it
guest/…/main.rsShows startup modes, guest-specific service assembly, and shutdown of background services.
guest/…/rpc.rsDefines the host-to-agent request and response surface.
guest/…/sandbox.rsShows prerequisite checks and sandbox message dispatch.
guest/…/sandbox.rsShows how the System VM composes the nested sandbox runtime with guest DNS, Docker, and forwarding hooks.
guest/…/port_forward.rsShows the guest half of sandbox port exposure and cleanup.
guest/…/Cargo.tomlShows which nested VM and Linux guest capabilities belong only to Linux builds.
guest/…/sandbox_service_manager.rsShows the end-to-end sandbox service lifecycle from create through execution and removal.
guest/…/port_forward_cleanup.rsShows the portable test entry for forwarding cleanup rules.