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 / rpc-and-protocols

RPC and protocols

ArcBox uses shared Protocol Buffer contracts to define control-plane messages and services. Those contracts reach the daemon through a local Unix socket and reach the guest agent through a framed host-to-guest channel over vsock. The RPC layer keeps these concerns separate: service contracts describe what components can ask for, connection layers select the endpoint, and transports carry the encoded bytes.

System boundary

The RPC system connects host applications, the daemon, the workload engine, and agents inside virtual machines. It supports a client-facing daemon API and an internal agent channel, while using common message definitions so lifecycle, runtime, sandbox, and diagnostic data have one shared meaning.

flowchart LR
    Client[Host client] -->|Connect, gRPC, or gRPC-Web| Socket[Daemon Unix socket]
    Socket --> Daemon[ArcBox daemon services]
    Daemon --> Engine[Workload engine]
    Engine -->|Framed RPC messages| Vsock[Vsock transport]
    Vsock --> Agent[Guest agent]
    Agent --> Guest[Guest runtime and workloads]

Protocol layers

Protocol definitions

Protocol Buffer files define the message shapes, service methods, streaming behavior, and compatibility rules shared by ArcBox components. The main arcbox.v1 package covers machine, agent, runtime, image, network, volume, migration, and system concerns. The arcbox.sandbox.v1 package separates sandbox control operations from process and file data operations. See Protocol and service contracts for the contract and code-generation view.

The protocol crate exposes generated message types to Rust consumers. The live daemon and Connect path use the Connect-generated message representation, while the prost-generated types remain available for typed test clients and wire-format checks. These representations come from the same source contracts and preserve the same Protocol Buffer bytes.

References: rpc/…/README.md• L3-31 rpc/…/lib.rs• L12-41 rpc/AGENTS.md• L32-43

Service contracts

Service contracts describe the operations that a caller can request and the events it can receive. Unary methods return one result. Streaming methods keep a connection open for readiness, lifecycle events, command output, file data, statistics, or migration progress.

The daemon registers the services that it implements on one Connect router. The generated service surface is broader than the active router because some declarations exist for shared schemas, tests, or future callers. Reflection exposes the declared service set so tools can discover the contract, but discovery does not mean that every service is available at runtime.

References: rpc/…/api.proto• L16-33 rpc/…/machine.proto• L17-127 rpc/…/agent.proto• L11-68 rpc/AGENTS.md• L18-31

Control-plane communication

Daemon API

The daemon exposes one local control-plane endpoint. The same handlers answer Connect requests, native gRPC requests, and gRPC-Web requests, which lets command-line tools use simple HTTP while typed clients use generated service clients.

The daemon serves this endpoint over a Unix domain socket. HTTP/1.1 supports Connect and gRPC-Web callers. HTTP/2 supports native gRPC and the streaming calls that need a long-lived bidirectional connection. Server reflection uses the same endpoint and descriptor set to describe the available contracts. Connect is the live serving path; generated tonic clients remain as compatibility and wire-format checks rather than as the daemon's serving layer.

References: app/…/control_plane.rs• L1-11 app/…/control_plane.rs• L32-67 rpc/…/lib.rs• L37-43 rpc/AGENTS.md• L18-31

Guest agent channel

The host-to-guest agent channel carries engine control requests into a running VM and returns replies or event frames. It uses the shared message definitions but is not a gRPC service at runtime: the declared AgentService is a schema description, while the live channel uses message-type identifiers and length-prefixed frames.

The engine owns the host client and the guest agent owns the dispatcher. This path handles agent health, runtime setup, Kubernetes control, filesystem lookup, shutdown, readiness, resource watches, storage observations, and sandbox operations. Streaming requests use a dedicated connection so the guest can send a sequence of events or data frames without mixing them with a separate unary exchange.

References: rpc/…/agent.proto• L1-68 guest/…/rpc.rs• L1-25 guest/…/rpc.rs• L37-125 engine/…/agent_client.rs• L1-10 rpc/AGENTS.md• L45-52

Connection layers

Daemon connection

The daemon connection joins a host client to the daemon's service router. A Unix socket gives the endpoint local process boundaries and avoids exposing the control plane as a network listener. The transport accepts concurrent requests and supports graceful draining when the daemon stops.

The connection layer is independent of the service meaning. A client selects a method from the generated contract, and the daemon's router maps that method to the matching service handler. If a declared service is not registered, the endpoint cannot serve it even though its messages and generated bindings exist.

References: rpc/…/README.md• L3-13 rpc/…/unix.rs• L11-35 app/…/control_plane.rs• L70-83 rpc/AGENTS.md• L18-31

Guest connection

The guest connection joins the engine to the agent inside a VM. Vsock addresses identify the guest context and the agent port. The default agent port is 1024, while the host and guest use different context IDs to identify their side of the VM boundary.

The transport presents a byte stream to the RPC client. The RPC layer adds the frame length, message type, trace identifier, and encoded payload. This split lets the same engine client work with real vsock file descriptors on Linux and VZ, or with the Hypervisor.framework socketpair path on macOS. A socket scope can interrupt dedicated guest connections during owner shutdown, including split async and blocking transports.

References: rpc/…/README.md• L3-14 rpc/…/mod.rs• L1-23 rpc/…/transport.rs• L88-105 rpc/…/socket_scope.rs• L7-18 engine/…/agent_client.rs• L88-105

Transport modes

The transport layer gives higher-level RPC code one connect, send, receive, and disconnect model. Unix sockets carry host-local daemon traffic. Vsock carries host-to-guest traffic. Raw vsock streams support callers that need a transparent full-duplex byte stream rather than framed RPC messages, such as tunnels.

The engine chooses an async or blocking mode from the VM backend. Async mode supports the full agent surface, including streams. The blocking mode is used for the Hypervisor.framework socketpair path and is intended for bounded unary work and readiness probes; it does not support streaming RPCs. Both modes use the same length-prefixed framing and 16 MiB receive limit. Scope close interrupts I/O but does not join the workers that own the connection.

References: rpc/…/lib.rs• L37-73 rpc/…/README.md• L30-50 rpc/…/README.md• L82-92 rpc/…/blocking.rs• L23-34 rpc/…/transport.rs• L13-18 engine/…/transport.rs• L6-75

Message flow

The following sequence shows how a host request becomes a guest action and returns a typed result. The daemon API path and the guest agent path share contract types, but they use different serving and framing rules.

sequenceDiagram
    participant C as Host caller
    participant D as Daemon router
    participant E as Engine agent client
    participant T as Unix/vsock transport
    participant A as Guest agent

    C->>D: Service request
    D->>E: Engine operation
    E->>T: Typed message as framed bytes
    T->>A: Length-prefixed frame
    A->>A: Decode and dispatch
    A-->>T: Response or event frame
    T-->>E: Framed bytes
    E-->>D: Typed result
    D-->>C: Response or stream item

Unary exchange

A unary exchange sends one request and waits for one response. The caller identifies the operation through the service method on the daemon path or through a message type on the agent path. The receiver checks the response type before decoding it, so a valid payload for the wrong operation is still an RPC error.

Error replies carry a status code and message that the engine maps into its error model. This keeps guest failures visible to the daemon instead of turning them into an unexplained decode or connection failure.

References: engine/…/agent_client.rs• L200-261 engine/…/agent_client.rs• L323-343 engine/…/wire.rs• L33-89

Streaming exchange

A streaming exchange keeps the connection open while the server sends a series of typed frames. Readiness streams report progress until a terminal state. Statistics, storage, and memory-pressure streams use repeated samples or events. Sandbox file and process operations use the same pattern for bulk or interactive data.

The caller must treat stream lifetime and backpressure as part of the contract. The agent uses trace identifiers to relate events to the request, and the engine bounds buffered stream data so a slow consumer does not allow unbounded memory growth.

References: rpc/…/agent.proto• L57-68 engine/…/agent_client.rs• L561-633 engine/…/agent_client.rs• L1252-1325 engine/…/agent_client.rs• L71-75

Compatibility boundary

Schema evolution

The host daemon and guest agent can be built or staged at different times. Their contracts therefore evolve through additive changes: new fields and methods can be ignored by older peers, but field removal and renumbering can break decoding or change meaning.

When a change alters the meaning of an existing agent message, the agent reports a new protocol version during Ping. The host checks that version before it treats the agent as ready. A new field that older peers can safely ignore does not require a protocol-version change.

References: rpc/…/README.md• L33-43 rpc/…/agent.proto• L70-89 engine/…/agent_client.rs• L345-387

Generated artifacts

Generated message types, service bindings, and the reflection descriptor must describe the same source contracts. The protocol and gRPC crates generate from the Protocol Buffer files. The Connect crate uses a committed descriptor set so its generated surface also works when the crate is built outside the workspace.

The descriptor is part of the contract boundary because reflection and Connect code generation depend on it. A protocol edit is not complete until the relevant generated outputs and descriptor are refreshed together. The committed prost output must also be regenerated and formatted because it is part of the source tree.

References: rpc/…/README.md• L25-31 rpc/…/arcbox.v1.rs• L1-15 rpc/…/protos.sha256• L1 rpc/AGENTS.md• L77-89

Change checklist

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

  • When a Protocol Buffer file changes, keep the protocol message output, gRPC bindings, Connect descriptor, and Connect-generated service surface aligned.
  • When a daemon service is added, register it on the API router as well as adding its contract and generated bindings. A missing registration produces an endpoint failure even when code generation succeeds.
  • When an agent RPC is added, update the message type mapping, guest dispatch, and engine client together. A schema-only AgentService change does not add a live agent call.
  • When an agent message changes meaning, update the host and guest protocol-version policy. Do not use the informational agent version as the compatibility gate.
  • When a transport changes, check both async and blocking backend paths. Keep the 16 MiB frame limit aligned, preserve socket leases through splits, and join workers after scope cancellation.

Important failure modes

TriggerConsequenceGuard
A daemon service is declared but not added to the Connect routerCalls return a service or method-not-found response on every supported formatRegister the service in the live API router and keep the router registration check current
A new agent operation changes only the protobuf service declarationNo live guest operation runs because the agent channel dispatches by MessageTypeUpdate the wire type, guest dispatcher, and AgentClient path
Protocol sources change without refreshing generated outputs or the Connect descriptorConsumers use stale message or service definitions, or the Connect build rejects the descriptorRebuild generated code and refresh the descriptor after source edits
A meaning-bearing agent change keeps the old protocol versionA mixed host and guest pair can pass the handshake and misread the requestBump the agent protocol version and keep the minimum-version check aligned
A streaming call uses the blocking agent transportThe call fails instead of producing readiness, event, process, or file framesSelect the async transport for streaming operations
Async and blocking transports use different frame limitsOne backend accepts a frame that another backend rejects, or allocates beyond the shared safety boundKeep the 16 MiB limit identical in both modes
A socket scope closes while split workers are not joinedSocket I/O stops but worker threads or tasks remain activeRetain the socket lease through both halves, close the scope, then join both workers

Key files

FileWhy to read it
rpc/…/agent.protoShows the guest-facing messages, health handshake, readiness and observation streams, and schema-only agent service declaration
rpc/…/machine.protoShows machine lifecycle and interactive execution contracts
rpc/…/api.protoShows daemon-facing system, migration, and streaming service contracts
rpc/…/common.protoShows shared policies and storage observation messages
rpc/…/README.mdStates the shared schema role and compatibility policy
rpc/…/lib.rsShows the public generated message namespaces and compatibility exports
rpc/…/arcbox.v1.rsShows the committed generated Protocol Buffer message output
rpc/arcbox-connect/descriptor/arcbox_connect.protosetShows the committed contract descriptor used by Connect and reflection
rpc/…/README.mdExplains transport usage, raw streams, relay framing, and cancellation behavior
rpc/…/transport.rsShows the async host-to-guest framed transport and split stream model
rpc/…/blocking.rsShows the blocking transport, deadlines, split workers, and frame limit
rpc/…/socket_scope.rsShows grouped socket cancellation and weak lease ownership
rpc/…/stream.rsShows raw stream behavior and platform-specific shutdown policy