S12-01 - Platform Interfaces
Purpose: How platform-specific code is isolated behind interfaces, and what each host OS uses for each.
Design
Section titled “Design”The cross-platform core never asks which OS it is on. It talks to a small set of interfaces. Each interface has one implementation per host OS:
| Interface | Responsibility | macOS | Windows | Linux |
|---|---|---|---|---|
VM provider (wb-vmd) |
Create, start, stop, save, restore VMs; disks; devices | Swift, Virtualization framework | Go, Host Compute Service (HCS) | Go, supervising a VMM over KVM (spike X10-linux-hypervisorX10-linux-hypervisor: Linux VMM and packet transportPick a permissively licensed VMM over KVM that supports vsock, save/restore, copy-on-write disks, and a virtual TPM (for Windows guests), and a way to deliver guest Ethernet frames to wb-netd as an unprivileged user (…; X16-openshell-linuxX16-openshell-linux: OpenShell for Linux guestsCould OpenShell's VM driver (libkrun, guest without a network device, egress over vsock) run Linux guests for Wraith Box on macOS and Linux hosts instead of a VMM chosen in X10-linux-hypervisor? checks OpenShell’s VM driver first) |
| Host-guest socket | Byte streams between wb-hostd and wb-guestd |
virtio-vsock (“Host-guest socket on macOS”) | Hyper-V sockets | virtio-vsock |
| Packet transport | Guest Ethernet frames to and from wb-netd, without host privileges |
file-handle network attachment (“Packet transport on macOS”) | spike X11-windows-hostX11-windows-host: Windows host through HCSOn Windows 11 Home with only the Virtual Machine Platform feature: can a standard user create, start, save, and restore a VM through HCS? | spike X10-linux-hypervisorX10-linux-hypervisor: Linux VMM and packet transportPick a permissively licensed VMM over KVM that supports vsock, save/restore, copy-on-write disks, and a virtual TPM (for Windows guests), and a way to deliver guest Ethernet frames to wb-netd as an unprivileged user (… |
| Disk cloning | Copy-on-write images (internal/platform/diskclone) |
APFS clones, fclonefileat |
VHDX differencing disks | qcow2 backing files, or reflinks where the filesystem supports them |
| Volume space | Free space and identity of a volume, the bytes a file takes, a file with its blocks allocated: the audit log’s free space and reserve (internal/platform/volspace, S09-11-auditS09-11-audit: AuditWhat the audit log records, the budgets that bound it, and what happens when the log can't be written.) |
statfs, lstat, fcntl(F_PREALLOCATE) |
refuses with errors.ErrUnsupported. The audit log then refuses VM starts, until Windows hosts are built |
statfs, lstat, fallocate |
| Socket receive queue | The bytes the kernel holds for a connected socket that no read has taken yet, counted by one call that returns at once: wb-proxyd’s check of a kept upstream connection (internal/platform/sockunread, S07-15-non-http-streamsS07-15-non-http-streams: Non-HTTP StreamsHow wb-proxyd checks the protocol of each stream, and what it does with SSH, other protocols and raw TCP., “Upstream failures”) |
getsockopt(SO_NREAD), which a Seatbelt profile that denies everything still allows |
1 when SIOCATMARK, asked first, says urgent data waits, and WSAIoctl(FIONREAD) otherwise |
1 when SIOCATMARK, asked first, says the queue is at the urgent mark, and ioctl(SIOCINQ), which stops at the mark, otherwise |
| Socket hang-up | Whether the peer of a connected AF_UNIX stream socket closed its end, not only shut down its writes. One call returns at once: wb-proxyd’s end of file on a stream’s socket. A second call blocks until the peer closes or the caller stops it, and never reads the socket: a relay waits with it for a close while it doesn’t read the socket (internal/platform/sockhangup, S07-20-handoff-socketsS07-20-handoff-sockets: Hand-off SocketsThe life of one VM's hand-off socket: its identity, the acknowledgments of both ends, how it closes, who a failure is charged to, what each restart does to it, and which of its decisions reach the audit log., “Stream bounds”). The blocking call holds one duplicate of the socket’s descriptor and one goroutine, and neither once it returns. An end it can’t tell, or a pending socket error (POLLERR), counts as a close. When the blocking call fails, as on a full descriptor table, its relay resets the stream with stream-hangup-wait-failed |
poll for POLLOUT with no wait, which reports POLLHUP once the peer closed. The blocking call asks the same each time Go’s network poller reports the duplicate readable. Both work under a deny-all Seatbelt profile (TestHungUpConfined) |
both calls refuse with errors.ErrUnsupported. The end counts as a close, and every raw or pass relay ends at once, reset with stream-hangup-wait-failed. Windows hosts hand off no streams yet |
poll with no wait, which reports POLLHUP once both ways are shut down. The blocking call waits on the duplicate as on macOS |
| Local IPC | Host gRPC endpoints, peer identity (internal/platform/localipc) |
Unix sockets in <data>/run, peer credentials |
named pipes, user-SID ACL, client process id | Unix sockets, SO_PEERCRED |
| Secret store | Holds every credential. Each item is readable only by the processes S15-least-privilegeS15-least-privilege: Least Privilege on the HostThe security design for SEC12-least-privilege: which rights Wraith Box takes on the host, where credentials are held, and how each host process gets only the credentials it needs, for only as long as it needs them. declares for it | Keychain | Credential Manager (DPAPI, per user) | Secret Service (D-Bus); see “Secret store on Linux without a desktop session” |
| Hardware key | Non-exportable CA signing key (S09-06-ca-keysS09-06-ca-keys: CA KeysHow the key of each TLS inspection certificate authority is made, stored and restored, and when a CA is valid., “Key”) | Secure Enclave, a key kept as its wrapped form in a store item | TPM via the CNG platform crypto provider | TPM 2.0 where present, else a software key in the secret store |
| Service manager | Run wb-hostd per user, at login and again whenever it exits. wb-hostd supervises the other daemons (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.) |
LaunchAgent nl.wraithbox.hostd, which wb setup writes (S17-install-and-upgradeS17-install-and-upgrade: Install, Downloads and UpgradesBuild, install, upgrade and remove a Wraith Box bundle, move its stored data to a new version, and download what an image build needs from the internet.) |
per-user logon task | systemd user unit |
| Self-sandbox | Confine our own daemons (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves.) | Seatbelt (“Self-sandbox on macOS”) | restricted token, job objects, AppContainer where it fits | Landlock and seccomp (no unprivileged user namespaces needed) |
| Image build downloads | Fetch what an image build needs from the internet: wb-download, never wb-hostd (S17-03-downloadsS17-03-downloads: DownloadsHow wb-download fetches what an image build needs from the internet.). On macOS, Apple’s installation service also asks Apple’s signing server (X30-installer-trustX30-installer-trust: Installer refusal of a changed restore imageDoes the Virtualization framework's macOS installer, run by wb-vmd-install, refuse a restore image that Apple didn't sign, or one with a changed or replaced component, and does the install contact Apple while wb-vmd-i…) |
“Image build downloads on macOS” | no Windows image download: the user supplies it (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., “What the matrix assumes”). The same program and host rules, confined with the Self-sandbox row’s mechanism, specified when Windows hosts are built | the same program and host rules, confined with Landlock and seccomp, specified when Linux hosts are built |
| Notifications | Approval prompts with actions | native helper (Swift) | native helper (S12-02-languages-and-ciS12-02-languages-and-ci: Languages and CIThe language used on each platform, and how CI builds each platform.) | freedesktop notifications over D-Bus from Go |
| Downloaded-file marker | Files leaving the guest other than via git | quarantine attribute | Mark of the Web | none (documented) |
| Paths | <config>, <data>, <logs> of S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves. (internal/platform/paths) |
~/.config/wraithbox, ~/Library/Application Support/WraithBox, ~/Library/Logs/WraithBox, where ~ is the home directory the user database gives the effective user ID, never HOME |
%APPDATA%\WraithBox, %LOCALAPPDATA%\WraithBox, %LOCALAPPDATA%\WraithBox\Logs |
$XDG_CONFIG_HOME/wraithbox, $XDG_DATA_HOME/wraithbox, $XDG_STATE_HOME/wraithbox/logs |
| Canonical path | The directory as one string: links resolved, names in their case on disk (platform.CanonicalDir). Project resolution compares paths in this form (S05-04-namingS05-04-naming: NamingHow wb identifies a project, a session and its branch, and how projects are registered, checked, moved and removed., “Resolving the key”) |
fcntl(F_GETPATH) on the open directory |
refuses with errors.ErrUnsupported, so project resolution refuses, until Windows hosts are built |
refuses with errors.ErrUnsupported, so project resolution refuses, until Linux hosts are built |
Host-guest socket on macOS
Section titled “Host-guest socket on macOS”- In the guest,
wb-guestdusesAF_VSOCKthroughgolang.org/x/sys/unix. - On the host,
wb-vmdpasses each connection towb-hostdas a Unix socket descriptor from Virtualization, with its ports.wb-hostdreceives it withinternal/platform/vmhandoff, which refuses a record that fails a check of 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”. On Linux and Windows hosts it returns an error that wrapserrors.ErrUnsupported. wb-hostdroutes only on the destination port.- The host opens every connection.
wb-vmddoesn’t register a host listener (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves., B29-vsock-handoffB29-vsock-handoff: Can wb-vmd hand guest connections to our Go daemons as descriptors, also across a restore?Yes, with conditions.).
Packet transport on macOS
Section titled “Packet transport on macOS”The network attachment uses a datagram socketpair (X18-vsock-handoffX18-vsock-handoff: Host-guest socket and descriptor hand-offCan wb-guestd, written in Go, open AFVSOCK sockets in a macOS guest?).
wb-vmdpasses the host end towb-hostd.wb-hostdpasses it to that VM’swb-netd(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.). A newwb-netdstarts for each start or restore.
Self-sandbox on macOS
Section titled “Self-sandbox on macOS”Each daemon applies a Seatbelt profile in its own process at start,
with sandbox_init_with_parameters, called without cgo. The call and
its deny probe are in internal/platform/selfsandbox
(S04-03-self-sandboxingS04-03-self-sandboxing: Self-SandboxingHow each host daemon confines itself at startup, and the wb-launcher that starts confined programs on macOS., “Confined first thing in main”).
A confined process can’t confine its children further. So wb-hostd
starts the other daemons through wb-launcher, which it starts before
it confines itself (X23-sandboxed-daemonsX23-sandboxed-daemons: Self-sandboxed Go daemons on macOSCan wb-netd, wb-proxyd and wb-hostd confine themselves at start with a sandbox profile, as S04-architecture says, while the Go runtime, inherited descriptors, and Keychain and Secure Enclave access in wb-proxyd keep w…).
A profile that reaches the Keychain allows two Mach services,
com.apple.securityd.xpc and com.apple.ctkd.token-client. One that
checks certificates allows com.apple.trustd.agent and the metadata of
its own bundle directory (S04-03-self-sandboxingS04-03-self-sandboxing: Self-SandboxingHow each host daemon confines itself at startup, and the wb-launcher that starts confined programs on macOS., “wb-proxyd and the
secret store on macOS”).
wb-vmd confines itself the same way, one per VM (X25-vmd-sandboxX25-vmd-sandbox: Self-sandboxed `wb-vmd`Can wb-vmd confine itself at start with a Seatbelt profile that allows the Virtualization framework, its VM bundles under <data>/vms and nothing else, and still create, start, save and restore a macOS VM?).
The function has no public header. The Swift code looks it up with
dlsym and calls it with the C calling convention. Its profile has:
- the Virtualization service;
- its VM’s bundle;
- the framework’s sandbox extensions.
Image build downloads on macOS
Section titled “Image build downloads on macOS”wb-download fetches:
- the restore image from Apple’s catalog;
- Claude Code from
downloads.claude.ai.
It runs with the network part of the wb-proxyd Seatbelt profile from
X23-sandboxed-daemonsX23-sandboxed-daemons: Self-sandboxed Go daemons on macOSCan wb-netd, wb-proxyd and wb-hostd confine themselves at start with a sandbox profile, as S04-architecture says, while the Go runtime, inherited descriptors, and Keychain and Secure Enclave access in wb-proxyd keep w… (I61I61 (closed): X23-sandboxed-daemons: wb-proxyd profile with Keychain and Secure EnclaveSplit from #34 (X23-sandboxed-daemons) during triage on 2026-10-04.), limited to port 443. It sets its own
file size limit first thing (internal/platform/filelimit).
- Go interfaces in
internal/platform, implemented in files with_darwin.go,_windows.go, and_linux.gosuffixes. Shared code never branches onruntime.GOOS. - One package for the descriptor channels. The
wb-vmdhand-off, thewb-launcherrequest channel, the stream hand-off and the accounting and event channels useinternal/platform/fdchan. Each message holds one record and at most one descriptor. The package refuses any other message and closes its descriptors (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., “Message form”). On macOS the socketpair isSOCK_DGRAM. - A native component is a separate process with a gRPC contract. It
is used only where Go can’t reasonably call the platform API. It
doesn’t make policy decisions or hold secrets. The one exception:
wb-vmdgets an image build’s provisioning password on a pipe, until its start call returns (S15-least-privilegeS15-least-privilege: Least Privilege on the HostThe security design for SEC12-least-privilege: which rights Wraith Box takes on the host, where credentials are held, and how each host process gets only the credentials it needs, for only as long as it needs them.). - Every platform implementation has the same conformance tests (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…). A platform is not “supported” until its conformance suite passes.
- Unimplemented platforms fail clearly. On a host or guest OS that
is “later” in the matrix,
wb setupand every command say so. Nothing half-works.
Host-guest socket: keeping wb-guestd’s endpoint
Section titled “Host-guest socket: keeping wb-guestd’s endpoint”On macOS and Linux guests, wb-guestd listens on a vsock port below
1024, which a project user can’t bind (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.,
X27-vsock-confinementX27-vsock-confinement: vsock confinement of project usersCan a non-root process in a macOS guest open AFVSOCK, and bind or listen on wb-guestd's port while wb-guestd is running or being restarted?). For other guests and hosts, spikes decide it:
- A Windows guest on a macOS or Linux host reaches the host over virtio-vsock through a Windows guest driver. X13-windows-guestsX13-windows-guests: Windows guests on a macOS hostCan the Virtualization framework boot Windows 11 for Arm in a supported way, including TPM and Secure Boot requirements and usable display and network drivers? checks whether that driver keeps low ports for privileged processes.
- Any guest on a Windows host uses Hyper-V sockets. They name a
service by GUID instead of a port number. X11-windows-hostX11-windows-host: Windows host through HCSOn Windows 11 Home with only the Virtual Machine Platform feature: can a standard user create, start, save, and restore a VM through HCS? decides
how the guest stops a project user from registering
wb-guestd’s service whilewb-guestdrestarts.
Secret store on Linux without a desktop session
Section titled “Secret store on Linux without a desktop session”Secret Service needs a running keyring, which headless or minimal
systems may lack. Without one, wb setup refuses to store credentials.
A TPM-sealed file is the candidate alternative. It needs its own spec.
Decisions
Section titled “Decisions”No credentials in a file without a keyring
Section titled “No credentials in a file without a keyring”wb setup refuses to store credentials on Linux without a keyring.
- Rejected: writing them to a file.
Status: Draft