Host-Guest Communication

Host and guest communicate over AF_VSOCK (port 1234) using the void-box-protocol crate. The protocol uses a simple length-prefixed binary framing. Most payloads are JSON, but Ping, Pong, and PtyData use raw bytes.

Frame Format

+---------------+-----------+--------------------+
| length (4 B)  | type (1B) | payload (N bytes)  |
+---------------+-----------+--------------------+
FieldSizeDescription
length4 bytesu32 little-endian, payload size only (excludes the 5-byte header)
type1 byteMessage type discriminant
payloadN bytesMessage payload. Usually JSON; Ping, Pong, and PtyData are raw bytes.

Message Types

Type ByteDirectionMessageDescription
0x01host → guestExecRequestExecute a command (program, args, env, timeout)
0x02guest → hostExecResponseCommand result (stdout, stderr, exit_code)
0x03host → guestPingSession authentication handshake. Raw payload: 32-byte secret plus optional 4-byte protocol version.
0x04guest → hostPongAuthentication reply with protocol version
0x05host → guestShutdownRequest guest shutdown
0x06host → guestFileTransferLegacy file transfer request
0x07guest → hostFileTransferResponseLegacy file transfer response
0x08guest → hostTelemetryDataGuest telemetry batch
0x09host → guestTelemetryAckTelemetry acknowledgement
0x0Ahost → guestSubscribeTelemetryStart telemetry stream
0x0Bhost → guestWriteFileWrite file to guest filesystem
0x0Cguest → hostWriteFileResponseWrite file acknowledgement
0x0Dhost → guestMkdirPCreate directory tree
0x0Eguest → hostMkdirPResponseMkdir acknowledgement
0x0Fguest → hostExecOutputChunkStreaming output chunk (stream, data, seq)
0x10host → guestExecOutputAckFlow control ack (optional)
0x11bothSnapshotReadyGuest signals readiness for live snapshot
0x12host → guestReadFileRead file from guest filesystem
0x13guest → hostReadFileResponseFile contents or error
0x14host → guestFileStatStat a guest file path
0x15guest → hostFileStatResponseFile metadata (size, mode, mtime)
0x16host → guestPtyOpenOpen interactive PTY session (program, args, env, interactive flag)
0x17guest → hostPtyOpenedPTY open result (success or error message)
0x18bothPtyDataRaw terminal I/O bytes (not JSON-encoded)
0x19host → guestPtyResizeTerminal window size change (cols, rows)
0x1Ahost → guestPtyCloseRequest PTY session close (sends SIGHUP to child)
0x1Bguest → hostPtyClosedPTY child exited (exit_code)

Note: PtyData is the only high-throughput stream message with raw bytes instead of JSON. Ping and Pong also use raw bytes for the session-secret and version handshake.

Security

MAX_MESSAGE_SIZE

64 MB — prevents OOM from untrusted length fields. Messages exceeding this limit are rejected before allocation.

Session Secret

32-byte hex token injected as voidbox.secret=<hex> in kernel cmdline. The guest-agent reads it from /proc/cmdline at boot and requires a successful Ping before the connection can send ExecRequest, file, PTY, or telemetry messages.

ExecRequest Debug Redaction

The Debug impl for ExecRequest redacts environment variables matching KEY, SECRET, TOKEN, PASSWORD patterns — preventing accidental credential exposure in logs.

Guest Networking

The vsock protocol above is backend-neutral. Guest IP behavior depends on the VM backend.

Linux/KVM

Linux/KVM uses smoltcp-based usermode networking (SLIRP) — no root, no TAP devices, no bridge configuration.

Guest VM                                    Host
+---------------------+                    +------------------+
| eth0: 10.0.2.15/24  |                    |                  |
| gw:   10.0.2.2      |-- virtio-net ------| SLIRP stack      |
| dns:  10.0.2.3      |   (MMIO)           | (smoltcp)        |
+---------------------+                    |                  |
                                           | 10.0.2.2 -> NAT  |
                                           |   -> 127.0.0.1   |
                                           +------------------+

Linux/KVM IP Details

EndpointAddressDescription
Guest IP10.0.2.15/24Static IP assigned to guest eth0
Gateway10.0.2.2Mapped to host 127.0.0.1 — guest reaches host services via this address
DNS10.0.2.3Forwarded to host resolver

Outbound TCP/UDP is NATed through the host. The guest reaches host services (e.g. Ollama on :11434) via 10.0.2.2.

macOS/VZ

macOS uses VZNATNetworkDeviceAttachment with DHCP inside the guest instead of the fixed SLIRP 10.0.2.x layout. In the current examples, the guest reaches host-local services through 192.168.64.1, but that addressing comes from the VZ NAT environment rather than the wire protocol itself.