S04 - Architecture
Purpose: Name the processes, the boundaries between them, and which requirement each boundary serves.
Requirements: SEC01-separate-kernelSEC01-separate-kernel: Separate kernelThe agent runs in a hardware-virtualized guest with its own kernel, never sharing a kernel with the host or with another environment of the user (for example a WSL distribution)., SEC02-no-host-fs-shareSEC02-no-host-fs-share: No host filesystem sharingNo host directory is mounted into the guest, read-only or otherwise., SEC05-default-denySEC05-default-deny: Default-deny egress, enforced on the hostOnly allowlisted hostnames are reachable., SEC15-no-guest-disk-mountSEC15-no-guest-disk-mount: The host never mounts a guest-written diskA disk image is guest-written once a guest has run with it attached, and every copy or clone of a guest-written image is guest-written too.
Tests: C11-host-daemonsC11-host-daemons: Host Daemons, Audit, and DisksThe test cases for the host daemons' own checks: wb-vmd's device set and slots, the image build bundle, supervision, the accounting and event channels, the daemon log pipes, the audit writer, free space, and the data…, C01-network-and-dnsC01-network-and-dns: Network and DNSThe test cases for the guest's network path: the link endpoint, addressing, and the DNS gateway with its hold, quiet refusals, and negative answers.
Briefs: B29-vsock-handoffB29-vsock-handoff: Can wb-vmd hand guest connections to our Go daemons as descriptors, also across a restore?Yes, with conditions., B34-sandboxed-daemonsB34-sandboxed-daemons: Can the Go daemons confine themselves on macOS?Yes, with conditions., B48-process-supervisionB48-process-supervision: Who restarts the host processes, and what happens to running VMs when one fails?Recommended that wb-hostd supervises the other daemons, that VMs are saved when wb-hostd stops and restored when it starts, and that every guest-facing handler gets a per-VM limit., B64-vmd-sandboxB64-vmd-sandbox: Can wb-vmd confine itself and still run a macOS VM?Yes, with conditions.
Overview
Section titled “Overview”Exactly two channels cross the VM boundary: the host-guest socket
(vsock on macOS and Linux, Hyper-V sockets on Windows; terminated by
wb-hostd) and Ethernet frames (terminated by wb-netd). There is
no shared directory, no NAT to the host network, and no other device
that carries data (SEC01-separate-kernelSEC01-separate-kernel: Separate kernelThe agent runs in a hardware-virtualized guest with its own kernel, never sharing a kernel with the host or with another environment of the user (for example a WSL distribution)., SEC02-no-host-fs-shareSEC02-no-host-fs-share: No host filesystem sharingNo host directory is mounted into the guest, read-only or otherwise., SEC05-default-denySEC05-default-deny: Default-deny egress, enforced on the hostOnly allowlisted hostnames are reachable.).
Processes
Section titled “Processes”Native user-interface helpers (notifications with actions, later a tray
or menu-bar item) are separate small processes per platform. They render
approval requests and return the user’s answer to wb-hostd, and decide
nothing themselves (S12-platformsS12-platforms: PlatformsWhich host and guest operating systems Wraith Box targets, how platform-specific code is isolated, what each platform uses, and how wb works inside WSL.).
Host state
Section titled “Host state”Locations follow each OS’s conventions (paths in S12-platformsS12-platforms: PlatformsWhich host and guest operating systems Wraith Box targets, how platform-specific code is isolated, what each platform uses, and how wb works inside WSL.); the logical layout is the same everywhere:
<config>/ user-editable configuration (S09-policy-credentials-audit) config.toml global settings and defaults policy.yaml global network policy (S09-policy-credentials-audit) projects/<project-id>.toml per-project settings but placement and config_trust, toolchain manifest reference projects/<project-id>.policy.yaml per-project network policy images/<name>.toml the recipe of a named image (S06-vm-lifecycle)<data>/ images/ base images (copy-on-write clones) images/macos-restore.ipsw the restore image a macOS image build installs from, fetched by wb-download (S17-install-and-upgrade) images/macos-restore.ipsw.partial the restore image while it downloads downloads/ a Claude Code release, or the Command Line Tools, during an image build (S14-claude-in-guest, S17-install-and-upgrade) images/macos-build.noindex/ the build VM's bundle, new for each image build, never listed as an image (S06-vm-lifecycle) vms/<guest-os>-{work,isolated}.noindex/ VM bundles: disks, machine identity, saved state projects/<project-id>/export.git bare repo the guest fetches from: selected refs only, written only by wb (S08-workspace-and-git) projects/<project-id>/landing.git bare repo receiving session branches (S08-workspace-and-git) state.db SQLite: the last VM generation of each slot (S04-02-vm-provider), projects with their key, identity, placement and config_trust (S05-04-naming), the project users of each data disk, their ID counter and the pending user removals (S06-03-image-updates), sessions, approvals, caches, the Go clock's point and tree heads (S07-egress-gateway), each VM's placeholder set until the VM is deleted (S09-policy-credentials-audit), each VM's CA records, the removal list of CA keys, on Linux whether the CA key is in a TPM (S09-policy-credentials-audit, S15-least-privilege), and the catalog entry of the restore image (S17-install-and-upgrade). Migrated by wb-hostd only, with its backups next to it as state.db.v<N>.bak (S17-install-and-upgrade). Mode 600 run/ user-only directory for local IPC endpoints<logs>/ audit JSONL, and one log per host process, <process>.log and its rotated files, all written by wb-hostd (S04-08-records-and-bounds)Inter-process contracts
Section titled “Inter-process contracts”Every message between processes is protobuf. A request with a reply
goes over gRPC. On the host it runs over a local IPC endpoint only the
user can open: Unix sockets in a 0700 directory on macOS and Linux,
named pipes with an ACL for the user’s SID on Windows. The peer’s
identity is checked on every connection. To the guest it runs over the
host-guest socket.
On macOS the endpoints are in internal/platform/localipc:
- The run directory is made with mode
0700when missing. One that isn’t a directory of the user without group or other permission bits, or is a symbolic link, is refused withipc-run-dir-unsafeand left as it is. - An endpoint is
<data>/run/<name>.sock. A listener holds an exclusive lock on<name>.lockfor its life, and a second one is refused withipc-endpoint-in-use. The lock holder removes a leftover socket of the user that refuses a connect, before its bind. Its close removes the socket before it releases the lock, so no listener removes another’s socket. A socket that answers is refused withipc-endpoint-in-use, and any other file at the path withipc-endpoint-unsafe. - Both ends check the other’s user ID, the listener on every accepted
connection and the dialer after its connect. A peer of another user
ID is closed with
ipc-peer-uidbefore a byte is read, and the listener goes on to the next connection. - The gRPC handshake refuses a connection that didn’t come through
these checks with
ipc-peer-unchecked.
gRPC can’t pass a descriptor. So a hand-off of descriptors is one record per message on a socketpair inherited at spawn (S04-02-vm-providerS04-02-vm-provider: VM Provider and StreamsHow wb-vmd hands guest connections and the NIC endpoint to other processes, the fixed device set of a VM, and where wb-proxyd takes a stream's identity from., “Hand-off on macOS”).
The .proto files in proto/ are the one contract for every language
(S10-tech-stackS10-tech-stack: Technology ChoicesFix languages, libraries, packaging, and repository layout, with the reason for each choice.):
| File | Package | Holds |
|---|---|---|
proto/wraithbox/vmd/v1/vmd.proto |
wraithbox.vmd.v1 |
VMService, served by wb-vmd and called by wb-hostd, and HandoffMessage and HandoffAck, the records of the hand-off channel |
proto/wraithbox/guest/v1/guest.proto |
wraithbox.guest.v1 |
GuestService, served by wb-guestd and called by wb-hostd. Its Shell runs the terminal stream to the guest, and its SetTime sets the guest clock |
proto/wraithbox/hostd/v1/hostd.proto |
wraithbox.hostd.v1 |
HostService, served by wb-hostd on its local IPC endpoint and called by wb |
proto/wraithbox/hostd/v1/shell.proto |
wraithbox.hostd.v1 |
ShellService, served by wb-hostd on the same endpoint and called by wb shell, for the terminal stream |
proto/wraithbox/hostd/v1/project.proto |
wraithbox.hostd.v1 |
ProjectService, served by wb-hostd on the same endpoint and called by wb, for project records (S05-04-namingS05-04-naming: NamingHow wb identifies a project, a session and its branch, and how projects are registered, checked, moved and removed.) |
proto/wraithbox/terminal/v1/terminal.proto |
wraithbox.terminal.v1 |
The frames of the terminal stream (S16-terminal-streamS16-terminal-stream: Terminal StreamHow wb guards boundary 6 of T00-index, the guest output that wb writes to the user's terminal., S05-02-exit-status-and-signalsS05-02-exit-status-and-signals: Exit Status and SignalsWhat wb claude exits with, and what it does with each signal.), the same on both hops. wb-hostd builds each frame it passes on new from a checked one |
proto/wraithbox/diskfmt/v1/diskfmt.proto |
wraithbox.diskfmt.v1 |
The messages between wb-hostd and wb-diskfmt, one per datagram on wb-diskfmt’s socketpair (S04-04-vm-processesS04-04-vm-processes: Per-VM ProcessesOne wb-vmd for each VM, the wb-vmd-layer entry of the Claude Code layer build, the wb-vmd-recipe entry of a named image's recipe, and wb-diskfmt, which formats a VM's new data disk., “wb-diskfmt”) |
proto/wraithbox/egress/v1/handoff.proto |
wraithbox.egress.v1 |
The messages of a VM’s hand-off socket between wb-netd and wb-proxyd (S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach., S07-06-name-mappingS07-06-name-mapping: Name MappingHow wb-proxyd keeps its own checked copy of the names wb-netd gave synthetic addresses: name reports, releases, replay, lifetime, the second count of the wildcard budget, and the copy wb-hostd keeps.) |
proto/wraithbox/egress/v1/control.proto |
wraithbox.egress.v1 |
The messages of the control channels between wb-hostd and wb-netd and wb-proxyd (“Control channels”) |
proto/wraithbox/egress/v1/accounting.proto |
wraithbox.egress.v1 |
The accounting records that wb-netd and wb-proxyd write to wb-hostd (S04-08-records-and-boundsS04-08-records-and-bounds: Records, Versions and BoundsThe records daemons send wb-hostd, the build version rules between processes, the bounds on host work a guest can cause, and logs., “Accounting and event channels”) |
A refusal over gRPC names its rule in a google.rpc.ErrorInfo detail,
as the reason, so the caller needn’t parse the message text. The
comments on each message from the guest, on HandoffMessage, and in
wraithbox.egress.v1 state the bounds the receiver checks.
Control channels
Section titled “Control channels”wb-netd and wb-proxyd each inherit a control channel from
wb-hostd at spawn: a socketpair of fdchan.Socketpair(4096), as for
the other descriptor channels. Each end sends the version record
first. The first message from wb-hostd is the daemon’s start
message, ProxydStart or NetdStart, and it comes once. A daemon
refuses another message before it, and a second one, and ends the
channel. wb-hostd treats a message from a daemon that it refuses as a
crash of that daemon (S04-07-supervisionS04-07-supervision: SupervisionWho starts and restarts each host process, what happens when wb-hostd stops or the bundle is upgraded, and daemon outages.).
wb-hostd logs a refused message with control-message-refused, and a
channel that fails with control-channel-failed. From wb-proxyd, it
also refuses an acknowledgment it didn’t ask for and a CA reply,
because it doesn’t send a CA request yet (I583I583 (closed): wb-hostd: run the CA keeper: boot order at VM start, ProxydStarted, the rotation tick and host wakeNamed by the code review of #581 (finding 1), which builds #507.). An acknowledgment that
comes after its call gave up is logged and ignored.
A record is at most 4 KiB and carries at most one descriptor. A
payload that doesn’t fit (an effective policy, a kept name mapping,
the wildcard sets) goes as the read end of a pipe. It holds a 4-byte
length and one protobuf message, and the reader refuses one over
64 MiB or not whole within 10 seconds. wb-hostd sends the read end
first, then writes the payload in a goroutine of its own under the same
10-second bound. A write that fails or times out is a crash of that
daemon. control.proto lists the
messages of each direction, and internal/egressmsg checks them.
Input from wb
Section titled “Input from wb”wb runs as the user, but what it sends wb-hostd about a project
comes from a repository, which anyone can have written. So
wb-hostd checks each field of a ProjectService request before it
reads state.db (SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.). A field over its cap is
refused with project-request-over-cap, and a field outside its form
with project-request-form. The refusal and its log name the field.
Input from wb |
Limits |
|---|---|
| A gRPC message | 4 MiB each way |
| The project key | the native realm only, a clean absolute path of at most 4,096 bytes of UTF-8 without a control character |
| The URLs of an identity | 1,024, each 1 to 8,192 bytes of printable ASCII without a space, 1 MiB together |
| The root commits of an identity | 1,024, each a 40- or 64-character lowercase object ID |
| A project id and name | 32 lowercase hexadecimal characters, and a name of S05-04-namingS05-04-naming: NamingHow wb identifies a project, a session and its branch, and how projects are registered, checked, moved and removed. of at most 64 bytes |
| Matching projects in a reply | 64, with the full count, and 8 ids in the refusal of an ambiguous name |
The version record
Section titled “The version record”On a host stream connection, gRPC included, each side sends its version
record first, then reads the peer’s (S04-08-records-and-boundsS04-08-records-and-bounds: Records, Versions and BoundsThe records daemons send wb-hostd, the build version rules between processes, the bounds on host work a guest can cause, and logs.,
“Between host processes”). On a datagram channel the first record is
the version record. The Go side is internal/hostversion. Go and Swift
write the same bytes:
- the four bytes
WBV1; - one length byte;
- that many bytes of the build version, 1 to 64 bytes, each from 0x20 to 0x7E. A length of 0 is an unstamped build, which has no version.
The reader takes at most 69 bytes, under a deadline of a few seconds (the value is in code). Until the peer’s record has passed, it hands nothing the peer sent to gRPC, and sends the peer nothing but its own record. Each refusal closes the connection and logs both versions, with its rule:
| Rule | When |
|---|---|
peer-version-timeout |
no whole record before the deadline: the peer sent none, the connection ended first, or the peer didn’t take this side’s record |
peer-version-malformed |
another magic, a length over 64, a version byte outside 0x20 to 0x7E, or, on a datagram channel, a first record that isn’t exactly one version record |
peer-version-unstamped |
the peer’s version is empty, or its own is empty or outside the form |
guest-version-form |
the peer’s version is not in the version form of S04-08-records-and-boundsS04-08-records-and-bounds: Records, Versions and BoundsThe records daemons send wb-hostd, the build version rules between processes, the bounds on host work a guest can cause, and logs., “The guest’s version is a label” (the rule Go’s version check names) |
peer-version-mismatch |
the versions differ as bytes |
Status: Draft