X18 - Host-guest socket and descriptor hand-off
Purpose: Whether wb-guestd in Go can use vsock in a macOS guest, and whether wb-vmd can hand vsock connections and the network endpoint to other processes as descriptors, also across save and restore.
For review
Section titled “For review”- Decides: the answer to X18-vsock-handoffX18-vsock-handoff: Host-guest socket and descriptor hand-offCan wb-guestd, written in Go, open AFVSOCK sockets in a macOS guest? (I29I29 (closed): X18-vsock-handoff: Host-guest socket and descriptor hand-offX18-vsock-handoff (added to S11-verification-and-spikes in #14)), and how the
hand-off works on macOS, which S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves., S06-vm-lifecycleS06-vm-lifecycle: VM Lifecycle, Images and the Guest AgentHow guest images are built, how VMs are kept warm, how projects and sessions map onto guests, and what wb-guestd does.
and 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. now state:
wb-vmdpasses each vsock connection and the host end of the network socket pair withSCM_RIGHTSand closes its own copy, and every host-guest connection ends at a restore, sowb-hostdreconnects towb-guestdafter each one. - You are approving: the answer “yes, with conditions”, the
measurements, and the spec text in this pull request. A suspended
idle guest answers gRPC from
wb-guestd4.1 s (p50) after the restore starts, which leaves about 2.9 s of the 7 s in NFR01-startupNFR01-startup: StartupGoals: a warm VM reaches the Claude prompt in about 4 s and a suspended VM in about 7 s, and no start takes more than 10 s (p95), excluding first-time project setup and the first boot after a host restart. for starting Claude Code. - Controls touched: none weakened. The hand-off keeps guest bytes
out of
wb-vmd’s code path (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves., SEC12-least-privilegeSEC12-least-privilege: Least privilege on the hostNo root or administrator rights at run time and no extra host user accounts.). They still pass through Apple’s Virtualization service process, as they always did. SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another. and SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter. depend onwb-hostdrouting only on the destination port, because the source port of a guest-initiated connection is the guest’s choice (condition 1). SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped. gets connection caps (condition 5). - Assumed: that a working guest restores about as fast as this
idle one to
wb-guestd(the state file was 1.44 GB). The time-to-prompt benchmark of S11-verification-and-spikesS11-verification-and-spikesthe filter's fuzz properties, including one that replays the filtered output and the exit reset into a headless emulator and checks it is back in its initial state, and a conformance case that prints every dropped seq… measures a working guest. That a non-root guest process can openAF_VSOCK, and that a Seatbelt profile can deny it (S13-guest-confinementS13-guest-confinement: Guest ConfinementControls inside the guest that narrow what a project user's processes can do, and tell the host which program opened each connection.). Neither was tried. - Open decisions:
- Guest-initiated connections: refuse them, so the host opens every connection (recommended, and enough for everything the spike needed), or bind each to a session with a one-time nonce from the host and close it on a mismatch. S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves. states both until this is decided.
- Brief: B29-vsock-handoffB29-vsock-handoff: Can wb-vmd hand guest connections to our Go daemons as descriptors, also across a restore?Yes, with conditions.
Question
Section titled “Question”From X00-indexX00-index: SpikesThe open questions that must be answered by a throwaway prototype before work builds on them, in the order they are taken up.: can wb-guestd, written in Go, open AF_VSOCK sockets
in a macOS guest? Do the file descriptors of a vsock connection and of
the file-handle network attachment keep working after wb-vmd passes
them to another process (SCM_RIGHTS), and across save and restore?
The maintainer’s comment on I29I29 (closed): X18-vsock-handoff: Host-guest socket and descriptor hand-offX18-vsock-handoff (added to S11-verification-and-spikes in #14) adds: measure the time from
restoreMachineStateFrom to the Go listener answering, from a fresh
APFS clone of the state and disks.
Answer
Section titled “Answer”Yes, with conditions. Each part, with the evidence in “Measurements”:
-
Go opens vsock in a macOS guest: yes.
golang.org/x/sys/unixhasAF_VSOCK,SockaddrVMandIOCTL_VM_SOCKETS_GET_LOCAL_CIDfor darwin, sowb-guestddoesn’t need cgo or a raw-syscall shim. A Go LaunchDaemon in the guest listened on port 1024, accepted connections, dialed the host (CID 2), and served gRPC on both. The guest’s CID was 3. The spike wraps each socket in anos.File, which the Go runtime poller handles. On the host,socket(AF_VSOCK)fails with “operation not supported by device”: host processes reach the guest only through Virtualization. -
A passed vsock descriptor works: yes. The descriptor that
VZVirtioSocketConnectiongives is not a vsock socket. It is a Unix-domain stream socket whose peer is Virtualization’s service process (com.apple.Virtualization.VirtualMachine), which moves the bytes to the virtual device.wb-vmdpassed it to a Go process, and the Go process kept working in each of these cases:wb-vmdkept the connection object open;wb-vmdcalledclose()on it right after the pass;wb-vmddropped its last reference withoutclose();wb-vmd’s main thread was blocked during the transfer;- the whole
wb-vmdprocess was stopped withSIGSTOPwhile the Go process echoed 8 MiB over gRPC (43 ms) and the network answered.
Connections the guest opens, accepted with
VZVirtioSocketListener, behave the same. Half-close works in both directions: either side canshutdown(SHUT_WR), the other reads to EOF and can still write (the assumption of X07-git-round-tripX07-git-round-trip: Git round tripRemote helper over vsock, read-only upload-pack, restricted receive-pack into the landing repository, flagging of risky paths.). -
A passed network descriptor works: yes.
wb-vmdpassed the host end of theSOCK_DGRAMsocket pair behindVZFileHandleNetworkDeviceAttachmentand closed its own copy at once. The Go process exchanged frames with the guest from then on. -
Save and restore: yes, with conditions.
- The VM saves with open connections. Resumed in the same VM, every passed descriptor and an open gRPC stream keep working.
- A restore ends every connection. When the saved VM stops,
every passed vsock descriptor of it reads EOF. In the restored VM,
the guest sees EOF on every connection it had at the moment it
resumes, while its listener keeps listening. A new connection is
accepted 5 ms after
resume, on the first try. - The restored VM gets a new network socket pair in its configuration (as in X02-warm-startX02-warm-start: Warm startMeasure time to restore a macOS guest from saved state with a vsock device and a file-handle network attachment.). Frames written to the old pair get no answer, and neither a read nor a write on it reports an error while the old VM object exists.
- From a fresh APFS clone, the guest listener accepts 3.97 s (p50)
and 4.15 s (p95) after the restore starts, and
wb-guestd’s gRPC health check answers through the Go process at 4.13 s and 4.21 s.
The conditions:
wb-hostdroutes only on the destination port. The receiving process sees a Unix socket, so it can’t read the vsock ports from it, andwb-vmdsends them with the descriptor. The destination port is onewb-hostdchose: a guest port it askedwb-vmdto connect to, or a host listener registered at its request. The source port of a guest-initiated connection is chosen by whatever guest process dialed, so it is only logged. Any guest process that can openAF_VSOCKcan dial a host listener, so guest-initiated connections are refused (recommended) or bound to a session by a one-time nonce from the host (open decision 1). S13-guest-confinementS13-guest-confinement: Guest ConfinementControls inside the guest that narrow what a project user's processes can do, and tell the host which program opened each connection. also deniesAF_VSOCKto project processes, as a second layer.- The hand-off channel carries one descriptor per message. The
spike framed requests as lines on a stream socket and attached the
descriptor to the first line, which can pair a descriptor with the
wrong request when two arrive together. The product uses a
SOCK_SEQPACKETorSOCK_DGRAMsocketpair inherited at spawn, with exactly one descriptor and the fields request id, VM generation, direction, source port and destination port in each message. The receiver refuses, closes and logs on a wrong descriptor count, a wrong socket type or a destination port it didn’t ask for (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves., contract in I52I52 (closed): S04-architecture, S09-policy-credentials-audit, S10-tech-stack: first .proto contracts and settings schemaS04-architecture says all IPC is protobuf over gRPC and S10-tech-stack adds proto/ "with the first RPC".). - Every restore starts new connections and a new VM generation.
wb-hostddrops itswb-guestdconnections when a VM is saved, and connects again after the restore. Beforeresume, it passes the new network descriptor towb-netdand resets that VM’s TCP flows and theirwb-proxydstreams (not the guest’s DHCP lease or its synthetic DNS name mapping, so the resumed guest’s cached answers still work), because the old descriptor never reports an error. Hand-off messages and audit entries carry the VM generation, and a message from an older generation is refused. wb-vmdmay close its copy of every passed descriptor at once. Nothing inwb-vmdhas to remain for a passed descriptor to work, except the VM itself. Note (2026-11-10): “at once” doesn’t hold for a socket still in flight. On macOS 27 the kernel can take a socket whose every reference is in a message as garbage, and the receiver gets it dead (I637I637 (closed): Descriptor senders close their copy before the receiver holds it (darwin socket GC)Found while fixing #633.).wb-vmdkeeps its copy of a passed socket untilwb-hostdholds it (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., “Transport”). After that, nothing inwb-vmdhas to remain.- Connections are capped.
wb-vmdcaps the connections it has accepted but not yet passed, per listener and in total, andwb-hostdcaps them per VM and per project. Both log each refusal (SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.). - The device set is fixed in
wb-vmd’s code. The contract never names a device type, so a request can’t add a NAT network or a shared directory to a VM.
Measurements
Section titled “Measurements”Host: Apple M2, 8 cores, 16 GB, macOS 27.0.1 (26A434), Go 1.27.1,
golang.org/x/sys 0.48.0, gRPC-Go 1.84.0. Guest: macOS 27.0.1, 4 vCPU,
4 GiB, the X02-warm-startX02-warm-start: Warm startMeasure time to restore a macOS guest from saved state with a vsock device and a file-handle network attachment. configuration (VZVirtioSocketDevice,
VZFileHandleNetworkDeviceAttachment on a datagram socket pair, a
64 GiB system disk and an 8 GiB data disk, both sparse). The guest was
provisioned once (see “How the listener got into the guest”) and then
sat at the login window. The clock starts before the
VZVirtualMachine is created, as in X02-warm-startX02-warm-start: Warm startMeasure time to restore a macOS guest from saved state with a vsock device and a file-handle network attachment..
| Measurement | p50 | p95 | Runs |
|---|---|---|---|
Restore, fresh clone: restoreMachineStateFrom done |
3.76 s | 3.95 s | 20 |
Restore, fresh clone: resume done |
3.97 s | 4.15 s | 20 |
| Restore, fresh clone: guest listener accepts | 3.97 s | 4.15 s | 20 |
Restore, fresh clone: wb-guestd gRPC answers through Go |
4.13 s | 4.21 s | 20 |
| Restore, fresh clone: guest answers on the network | 3.98 s | 4.16 s | 20 |
| First gRPC health check after restore | 155 ms | 188 ms | 20 |
| Cold boot, fresh clone: guest listener accepts | 10.93 s | 13.48 s | 10 |
saveMachineStateTo, 4 GiB, idle guest |
3.06 s | 1 |
- Every restore connected on the first try, so the listener was up the moment the guest ran. The restore times match X02-warm-startX02-warm-start: Warm startMeasure time to restore a macOS guest from saved state with a vsock device and a file-handle network attachment.’s 3.71 s and 3.92 s to the network within 0.3 s.
- The first gRPC call on a new connection after a restore took about 155 ms. Later calls took about 1 ms or less. The spike didn’t find out where the 155 ms goes.
- A cold boot reached the network at about 5 s and the listener at
about 11 s. The guest daemon starts about 10 s into the boot, and its
first
listensucceeds. - Throughput on a passed descriptor: 8 MiB echoed through gRPC in 43 to 70 ms.
- Restore fails while the host is locked. In the first try of the
restore series, all 20 restores failed with “The virtual machine
failed to restore with error permission denied” (
VZErrorRestore, code 12, the code of every restore failure), and the system log shows the Secure Enclave key refused (-25308,errSecInteractionNotAllowed) in Virtualization’s service process (results/restore-4g-failed-syslog.txt). That is the error X02-warm-startX02-warm-start: Warm startMeasure time to restore a macOS guest from saved state with a vsock device and a file-handle network attachment. saw when saving on a locked host. The second try waited for an unlock before each run and logged the lock state (results/restore-4g.jsonl.lock, unlocked for every run), and 20 of 20 restores of the same state worked. X02-warm-startX02-warm-start: Warm startMeasure time to restore a macOS guest from saved state with a vsock device and a file-handle network attachment. had assumed this. - The guest clock lags after a restore. Right after one restore,
the guest’s wall clock was 9.5 s behind the host’s, about the time
the VM had been saved and stopped. S06-vm-lifecycleS06-vm-lifecycle: VM Lifecycle, Images and the Guest AgentHow guest images are built, how VMs are kept warm, how projects and sessions map onto guests, and what wb-guestd does. already has
wb-guestdset the guest clock after a restore.
How the listener got into the guest
Section titled “How the listener got into the guest”A stock guest runs nothing on vsock (X02-warm-startX02-warm-start: Warm startMeasure time to restore a macOS guest from saved state with a vsock device and a file-handle network attachment.). This spike used
VZMacGuestProvisioningOptions, new in macOS 27: the first boot after
installing creates a user with Remote Login on. The setup script then
connected over SSH, on a NAT network that only this setup boot had,
installed the daemon as a root LaunchDaemon with sudo, and shut the
guest down. It took 38 to 40 s from the first boot. No host process
mounted a guest disk. This is a shortcut for the spike, not the product
path, which X17-image-buildX17-image-build: Unattended image buildCan a macOS guest installed from an Apple restore image get past Setup Assistant, with wb-guestd running as a root LaunchDaemon, without SSH, scripted clicks, or MDM? decides. It is evidence for X17-image-buildX17-image-build: Unattended image buildCan a macOS guest installed from an Apple restore image get past Setup Assistant, with wb-guestd running as a root LaunchDaemon, without SSH, scripted clicks, or MDM?
that provisioning works on a macOS 27 host and guest. The provisioned
bundles have Remote Login on and an admin user with a password, so no
product image may descend from them.
What was not measured
Section titled “What was not measured”- A working guest. Every state came from a guest idle at the login window. The time-to-prompt benchmark of S11-verification-and-spikesS11-verification-and-spikesthe filter's fuzz properties, including one that replays the filtered output and the exit reset into a headless emulator and checks it is back in its initial state, and a conformance case that prints every dropped seq… restores a working guest’s state.
wb-vmdexiting. Virtualization runs the VM on behalf of the process that created it, so the VM is expected to stop withwb-vmd, and the passed descriptors to read EOF, which no run tried.net.FileConnon a vsock descriptor in the guest. The spike usedos.NewFileand its ownnet.Connwrapper. On the host, a passed descriptor is a Unix socket, whichnet.FileConnhandles.- Restore after a host restart or update, as in X02-warm-startX02-warm-start: Warm startMeasure time to restore a macOS guest from saved state with a vsock device and a file-handle network attachment..
What it means for the specs
Section titled “What it means for the specs”- S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves., “The VM provider passes descriptors, not bytes”: states what the macOS descriptor is, the hand-off channel, routing on the destination port, the two ways to handle guest-initiated connections, the connection caps, the fixed device set, and what a restore does (changed in this pull request).
- 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 host-guest socket and packet transport rows
for macOS name the mechanism and this spike, and agree with
S07-egress-gatewayS07-egress-gateway: Egress GatewayThe only path from a guest to any network: a userspace network stack (wb-netd) and a policy-enforcing proxy (wb-proxyd) on the host. that the network descriptor reaches
wb-netdthroughwb-hostd(changed in this pull request). - S06-vm-lifecycleS06-vm-lifecycle: VM Lifecycle, Images and the Guest AgentHow guest images are built, how VMs are kept warm, how projects and sessions map onto guests, and what wb-guestd does., “Warm start”: restore while locked is now
measured, permanence of a failed restore is decided from the host identity and build recorded with the state, and
wb-hostdreconnects towb-guestdafter each restore (changed in this pull request). - S13-guest-confinementS13-guest-confinement: Guest ConfinementControls inside the guest that narrow what a project user's processes can do, and tell the host which program opened each connection.: the session profile denies
AF_VSOCK(changed in this pull request). - NFR01-startupNFR01-startup: StartupGoals: a warm VM reaches the Claude prompt in about 4 s and a suspended VM in about 7 s, and no start takes more than 10 s (p95), excluding first-time project setup and the first boot after a host restart.: fits for an idle guest. 4.1 s to
wb-guestdanswering leaves about 2.9 s of the 7 s for a suspended VM. Its text changed on I111I111 (closed): NFR00-index: write the performance requirements as goals, like NFR02-fs-speedX18-vsock-handoff measured a cold boot to wb-guestd at 10.93 s (p50) and 13.48 s (p95), against the 10 s hard ceiling (p95) of NFR01-startup (#86). (see “Cold boot” below). - Cold boot: about 11 s to
wb-guestd(p95 13.5 s) is above the 10 s ceiling of NFR01-startupNFR01-startup: StartupGoals: a warm VM reaches the Claude prompt in about 4 s and a suspended VM in about 7 s, and no start takes more than 10 s (p95), excluding first-time project setup and the first boot after a host restart., if a cold boot after a failed restore counts against it. NFR01-startupNFR01-startup: StartupGoals: a warm VM reaches the Claude prompt in about 4 s and a suspended VM in about 7 s, and no start takes more than 10 s (p95), excluding first-time project setup and the first boot after a host restart. excludes only the first boot after a host restart. The image work of X17-image-buildX17-image-build: Unattended image buildCan a macOS guest installed from an Apple restore image get past Setup Assistant, with wb-guestd running as a root LaunchDaemon, without SSH, scripted clicks, or MDM? should look at how early the LaunchDaemon starts (I86I86 (open): Cold boot to wb-guestd takes about 11 s, above the NFR01-startup ceilingFound by X18-vsock-handoff (#29).). Decided 2026-10-06 (I111I111 (closed): NFR00-index: write the performance requirements as goals, like NFR02-fs-speedX18-vsock-handoff measured a cold boot to wb-guestd at 10.93 s (p50) and 13.48 s (p95), against the 10 s hard ceiling (p95) of NFR01-startup (#86).): the figures of NFR01-startupNFR01-startup: StartupGoals: a warm VM reaches the Claude prompt in about 4 s and a suspended VM in about 7 s, and no start takes more than 10 s (p95), excluding first-time project setup and the first boot after a host restart. are goals that V1-M6-release-gateV1-M6-release-gate: Release gateThe Seatbelt profiles of wb-hostd and the sessions, confinement self-checks, warm start and suspend, the full conformance suite and benchmarks, packaging and upgrades. doesn’t pass or fail on, and NFR01-startupNFR01-startup: StartupGoals: a warm VM reaches the Claude prompt in about 4 s and a suspended VM in about 7 s, and no start takes more than 10 s (p95), excluding first-time project setup and the first boot after a host restart. states the cold boot measured here.
Spike code
Section titled “Spike code”Branch spike/x18-vsock-handoff, at
6312bbc:
the Swift wb-vmd stand-in, the Go guest daemon and host receiver, the
provisioning script, the series script, and the raw results in
results/ with their p50 and p95 in results/stats.txt.
Status: Answered 2026-10-05: yes, with conditions