S04-04 - Per-VM Processes
Purpose: One 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. The wb-vmd-install entry of an image build is in
S04-10-vmd-installS04-10-vmd-install: Installing macOS in `wb-vmd`The wb-vmd-install entry of an image build: its install rules, the restore image it reads, the build bundle it installs into, and its Install call..
Design
Section titled “Design”One wb-vmd per VM
Section titled “One wb-vmd per VM”Each VM has its own wb-vmd. wb-launcher has two fixed entries for
them, wb-vmd-work and wb-vmd-isolated:
- Each has that VM’s bundle as its profile parameter:
<data>/vms/macos-work.noindexor<data>/vms/macos-isolated.noindex. - Each has an instance cap of one.
The slot
Section titled “The slot”Each instance learns its slot from the WB_VMD_SLOT environment
variable. The variable is part of its launcher entry’s fixed
environment:
| Entry | WB_VMD_SLOT |
|---|---|
wb-vmd-work |
work |
wb-vmd-isolated |
isolated |
wb-vmd-install (S04-10-vmd-installS04-10-vmd-install: Installing macOS in `wb-vmd`The wb-vmd-install entry of an image build: its install rules, the restore image it reads, the build bundle it installs into, and its Install call.) |
build |
wb-vmd-layer (“wb-vmd-layer”, below) |
layer |
wb-vmd-recipe (“wb-vmd-recipe”, below) |
recipe |
The slot never comes from the program path or a request. So the slot
and the bundle come from the same table entry. On hosts without
wb-launcher, wb-hostd sets WB_VMD_SLOT when it starts wb-vmd,
and the same refusals apply.
wb-hostd creates each bundle directory, never as a symbolic link,
before it asks wb-launcher to start the entry. It checks the path
with lstat and never follows it. A symbolic link, or anything but a
directory, refuses the start with vm-bundle-not-directory. It creates
a new, empty build bundle before each build.
Slot checks
Section titled “Slot checks”Before it confines itself, wb-vmd refuses to start, logs the rule
and exits:
- on a macOS older than 27 (
vmd-host-unsupported, S02-05-swift-contracts-dotnetS02-05-swift-contracts-dotnet: Swift, Contracts and .NETWhere the Swift toolchain comes from, the Swift tasks, the contract tools, and the .NET toolchain to come.); - when the variable is missing (
vmd-slot-missing); - when it holds any other value (
vmd-slot-unknown); - in a test build, when the test data root linked into it is
missing or not an absolute path (
vmd-test-data-invalid, S06-05-disksS06-05-disks: DisksA VM's system disk and data disk: how the data disk keeps what the guest flushes, and how the guest mounts it., “Test data root”); - when its bundle path isn’t a directory (
vmd-bundle-missing); - when the real path of that bundle isn’t that slot’s bundle under the
real path of
<data>(vmd-slot-bundle-mismatch). An example is a bundle that is a symbolic link to another VM’s bundle.
So it never confines itself to a bundle its slot doesn’t own (SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another.). 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… tests each rule.
wb-vmd-install serves build. It has the install rules and the
restore image check (S04-10-vmd-installS04-10-vmd-install: Installing macOS in `wb-vmd`The wb-vmd-install entry of an image build: its install rules, the restore image it reads, the build bundle it installs into, and its Install call.). Until the layer build
is built (V1-M7-image-buildV1-M7-image-build: Image buildwb image build downloads the restore image and the Command Line Tools, installs and provisions a VM over the build network, installs the minimal base layer, and installs Claude Code in its own top layer.), wb-vmd refuses the layer slot
(vmd-slot-layer-unsupported). wb-vmd-layer alone serves layer. It
has no install rules and no restore image check, and it uses the build
bundle too (“wb-vmd-layer”, below). Until the recipe build is built,
wb-vmd refuses the recipe slot as well
(vmd-slot-recipe-unsupported), and wb-vmd-recipe alone serves it.
Reaching an instance
Section titled “Reaching an instance”wb-hostd reaches each instance only over the channels it handed that
instance at spawn: its control channel and its hand-off socketpair
(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., “The VM provider passes descriptors, not bytes”).
The channel a message arrives on says which VM it’s about. No request
names a VM, a slot, or a path.
wb-hostd cuts each text a wb-vmd returns, in a refusal or a
framework error, to a fixed bound before it logs it or passes it on.
wb-hostd treats the contents of every VM bundle as written by a
possibly compromised wb-vmd. It opens, clones and deletes files in a
bundle without following symbolic links. It checks a file’s identity
before it uses one, as for the sealed disk of an image build
(S06-02-image-buildS06-02-image-build: Image BuildHow wb image build makes a guest image: the build VM, its two provisioning stages, terminfo, sealing, and storage., “Built by Wraith Box”).
wb-vmd-layer
Section titled “wb-vmd-layer”The Claude Code layer build boots a clone of a sealed parent image
(S06-01-image-layersS06-01-image-layers: Image Layers and the Toolchain PrefixThe layers of a guest image, and the toolchain prefix that project layers install into., “The Claude Code layer”). It installs nothing
from a restore image, so it doesn’t run in wb-vmd-install. It runs
in a fourth fixed entry, wb-vmd-layer:
- Its compiled-in profile is the
wb-vmdprofile of the session VMs, without any of the install rules (SEC12-least-privilegeSEC12-least-privilege: Least privilege on the hostNo root or administrator rights at run time and no extra host user accounts.). - Its profile parameter is the build bundle,
<data>/images/macos-build.noindex, and itsWB_VMD_SLOTislayer, a slot of its own. It doesn’t check for a restore image. - Its instance cap is one.
wb-hostdnever starts it whilewb-vmd-installruns, because the two share the bundle and one maintenance VM runs at a time (S06-07-slot-admissionS06-07-slot-admission: Slot AdmissionHow wb-hostd admits every macOS VM it starts against the limit of two, and lends the isolated VM's slot to a maintenance VM.). - The VM it boots has no network device.
wb-guestdgets the binary over the host-guest socket. Only when the start call’s Xcode flag is set, it attachesxcode.imgread-only (S06-14-xcode-imageS06-14-xcode-image: The Xcode ImageHow an image gets full Xcode and the simulator runtimes from the host, as a read-only disk the host builds, and who runs Xcode's first launch.). - Its slot refuses provisioning options, and it logs
vmd-provisioning-refused, as a session VM’swb-vmddoes.
wb-hostd clones the parent into the new, empty build bundle with the
identity check of S06-02-image-buildS06-02-image-build: Image BuildHow wb image build makes a guest image: the build VM, its two provisioning stages, terminfo, sealing, and storage., “Taking the sealed image”.
wb-vmd-recipe
Section titled “wb-vmd-recipe”A named image’s recipe runs in a clone of its parent with a network
(S06-17-named-imagesS06-17-named-images: Named Images and RecipesThe build of a named image from a recipe on a clone of the sealed base., “The recipe VM”). It runs in a fifth fixed
entry, wb-vmd-recipe, which differs from wb-vmd-layer only in
these:
- Its
WB_VMD_SLOTisrecipe, a slot of its own, and its profile parameter is the build bundle too.wb-hostdnever starts it whilewb-vmd-installorwb-vmd-layerruns. - The VM it boots has one network device, whose hand-off socket goes
to the recipe VM’s own
wb-netd(S06-17-named-imagesS06-17-named-images: Named Images and RecipesThe build of a named image from a recipe on a clone of the sealed base., “The network of a recipe build”). - It has no Xcode flag, and refuses a start call that sets one with
vmd-xcode-disk-refused, as every slot butlayerdoes.
So wb-vmd-layer’s VM never has a network device, whatever a start
call says.
wb-diskfmt
Section titled “wb-diskfmt”wb-diskfmt formats a VM’s new data disk (S06-13-data-disk-formatS06-13-data-disk-format: Data Disk FormatHow the host formats a VM's new data disk, the one exception SEC15-no-guest-disk-mount makes, and the checks before a VM starts with its disk.,
X08-data-diskX08-data-disk: Data disk for homesGuest user homes on a second disk, surviving a system-disk replacement.), or an image build’s Xcode disk (S06-15-xcode-diskS06-15-xcode-disk: The Xcode DiskHow the host builds the read-only disk that holds Xcode and the simulator runtimes for an image build, under the wb-diskfmt shim's profile, and what the build records.).
wb-launcher has three fixed entries, wb-diskfmt-work,
wb-diskfmt-isolated and wb-diskfmt-xcode. Each takes no arguments,
and has its slot’s bundle as its profile parameter (the build bundle
and, for xcode, the parameters in S06-15-xcode-diskS06-15-xcode-disk: The Xcode DiskHow the host builds the read-only disk that holds Xcode and the simulator runtimes for an image build, under the wb-diskfmt shim's profile, and what the build records., “The entry”), and an
instance cap of one. Its shim is started as the
leader of a new process group, so that its parent can kill the shim
with the diskutil it runs (S06-13-data-disk-formatS06-13-data-disk-format: Data Disk FormatHow the host formats a VM's new data disk, the one exception SEC15-no-guest-disk-mount makes, and the checks before a VM starts with its disk., “When
wb-diskfmt doesn’t exit”). On hosts without wb-launcher,
wb-hostd starts the entry itself, with the entry’s fixed environment
and descriptors, as it starts wb-vmd.
Its start interface:
- no arguments;
WB_DISKFMT_SLOT,work,isolatedorxcode, in the entry’s fixed environment, asWB_VMD_SLOTis forwb-vmd(“The slot” above);- descriptor 2, its log pipe (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., “Daemon logs”);
- descriptor 3, one end of a Unix datagram socketpair for the exchange
with
wb-hostd,proto/wraithbox/diskfmt/v1. Each datagram holds one message, and none carries a descriptor.
Before it confines itself, wb-diskfmt refuses to start, logs the
rule and exits:
- with an argument (
diskfmt-arguments); - when the variable is missing (
diskfmt-slot-missing); - when it holds any other value (
diskfmt-slot-unknown); - when its slot’s bundle path doesn’t exist or isn’t a directory
(
diskfmt-bundle-missing); - when the real path of that bundle isn’t that slot’s bundle under the
real path of
<data>(diskfmt-slot-bundle-mismatch).
It finds <data> from the home directory in the user database, never
HOME. 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… has a test for each rule.
- As
wb-vmddoes, it resolves the bundle path withrealpathto get its profile parameter. It reads nothing fromwb-hostdbefore it confines itself. - After that, it exchanges version records with
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., “Between host processes”). A data disk entry receives the disk’s size in GiB, and refuses a size outside the bounds in code withdiskfmt-size-invalid. - A data disk entry sends the volume UUID back, renames the file when
wb-hostdasks, and exits. The Xcode entry’s exchange (its size, the check-only request, and the version, build and hashes it reports) is in S06-15-xcode-diskS06-15-xcode-disk: The Xcode DiskHow the host builds the read-only disk that holds Xcode and the simulator runtimes for an image build, under the wb-diskfmt shim's profile, and what the build records., and joinsdiskfmt/v1in IMG.8.
wb-hostd treats each answer as untrusted. It accepts a volume UUID
only in canonical form, and a name only when it is the fixed one, and
it cuts a refusal’s text to a fixed bound.
wb-diskfmt’s profile
Section titled “wb-diskfmt’s profile”The compiled-in profile allows:
- reading and writing the data disk’s temporary and final names in that bundle, and reading the bundle directory’s metadata. The bundle’s other files are guest-written, and the shim can’t open them;
- its inherited descriptors;
- starting
/usr/sbin/diskutiland no other program, with the system’s libraries and settings read-only, and listing the root directory, which dyld reads to find the shared cache; - the metadata of the
/dev/disk*nodes, whole disks and slices, but not their contents; - the services
diskutilreaches: the disk image controller, Disk Arbitration,storagekitd, and Authorization Services (com.apple.authd), which the attach asks.
The file rules bind only the shim’s own opens. The disk services run outside the sandbox and act on the disk a request names, so a subverted shim could erase, mount or unmount any disk the host user may, and list the host’s disks. Seatbelt can’t filter what a request to a service asks for, so the profile can’t narrow that.
The authd rule lets a subverted shim ask for authorization rights.
A right that needs authentication shows a real administrator password
dialog, and gains nothing unless the user enters a password. A right
that doesn’t is granted to an administrator’s session without a
dialog, which is within the host user’s own powers. diskutil can’t
attach an image without that service (I353I353 (closed): wb-diskfmt: measure its sandbox profile on the host and decide the iokit-get-properties rulePR #352 (#289) gives wb-diskfmt a self-sandbox profile (packages/wraithbox-go/cmd/wb-diskfmt/profile.go) that no confined run has measured yet.).
These rest on the shim’s inputs: it takes no guest input, only
wb-hostd’s request, and it exits after one format and is never
restarted. It denies the network and every other file, except the
Xcode entry’s reads and programs in S06-15-xcode-diskS06-15-xcode-disk: The Xcode DiskHow the host builds the read-only disk that holds Xcode and the simulator runtimes for an image build, under the wb-diskfmt shim's profile, and what the build records.. The Xcode entry
also reaches com.apple.trustd.agent, which codesign needs. That
service runs outside the sandbox and may fetch from the network to
evaluate a certificate, so a subverted shim can make the host user’s
trust service fetch on its behalf (S06-15-xcode-diskS06-15-xcode-disk: The Xcode DiskHow the host builds the read-only disk that holds Xcode and the simulator runtimes for an image build, under the wb-diskfmt shim's profile, and what the build records., “The profile”).
The service names are in code.
They were measured on macOS 27 with the opt-in host test, which runs a
confined format (I228I228 (closed): X08-data-disk follow-up: measure that a host-made data volume stays unencrypted and returns freed spaceX08-data-disk (PR #227) recommends option A: the host formats the data disk as APFS.).
wb-diskfmt’s kill
Section titled “wb-diskfmt’s kill”wb-hostd keeps the wait for the shim’s answer, and decides when a
shim that doesn’t exit is killed (S06-13-data-disk-formatS06-13-data-disk-format: Data Disk FormatHow the host formats a VM's new data disk, the one exception SEC15-no-guest-disk-mount makes, and the checks before a VM starts with its disk., “When
wb-diskfmt doesn’t exit”). On macOS it can’t send the kill. Its
profile denies signal to other processes, and it isn’t the parent,
so it can’t tell whether the shim was reaped. So it asks wb-launcher
on the request channel, in one fixed-format request that names the
entry and the instance ID (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., “Who starts whom”).
- Refused.
wb-launcherrefuses a kill for an entry other than thewb-diskfmtentries, and for an instance ID it never returned. It signals nothing, and logs the refusal with the rulelauncher-kill-refused. - Already exited. For an instance it started and has reaped, it signals nothing. Instance IDs aren’t reused (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., “Who starts whom”), so that ID can’t name a newer shim.
- Sent. Otherwise, while it hasn’t reaped the shim, it sends
SIGKILLto the shim’s process group and to the shim, and logs the decision with the rulelauncher-kill. The shim’s ID, which is also the group’s ID, isn’t reused before that reap. - The answer. Its answer is one of: sent, already exited, refused
with its rule, or the signal failed. The exit report may come before
the answer or after it, and
wb-hostdmatches the two by instance ID.
Where wb-launcher writes the lines for launcher-kill and
launcher-kill-refused is decided in M3.11. They don’t go only through
wb-hostd, so the wb-hostd that asked for a kill can’t hide it.
wb-hostd bounds its wait for the answer and for the exit report. No
answer in time, or the end of the request channel, counts as a kill
that failed. wb-hostd then logs data-disk-shim-exit with that
outcome, as it does when its own kill fails today. Each outcome, the
launcher’s rule included, is in that line (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.).
Without wb-launcher, wb-hostd is the parent, and sends the kill
itself under the same gate.
Decisions
Section titled “Decisions”One wb-vmd per VM, not one for both
Section titled “One wb-vmd per VM, not one for both”- Why: one
wb-vmdfor both VMs would let a compromise that starts in the isolated VM reach the work VM’s disks and saved state. It would get there through framework code that runs inwb-vmd’s process. That breaks the separation SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another. puts the isolated VM there for. - Decided: I64I64 (closed): X25-vmd-sandbox: Self-sandboxed wb-vmdFound while answering #34 (X23-sandboxed-daemons)., B64-vmd-sandboxB64-vmd-sandbox: Can wb-vmd confine itself and still run a macOS VM?Yes, with conditions..
Status: Draft