S06-02 - Image Build
Purpose: How wb image build makes a guest image: the build VM,
its two provisioning stages, terminfo, sealing, and storage.
Design
Section titled “Design”Built by Wraith Box
Section titled “Built by Wraith Box”wb image build installs macOS into a new VM from a restore image in a
local file. Then it provisions the VM in two stages (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?).
Builds are scripted and repeatable. Nobody configures an image by hand.
The build VM runs in the fixed build bundle
<data>/images/macos-build.noindex. It never runs in a session VM’s
bundle, or in a path from a request.
Its wb-vmd is started through the fixed wb-launcher entry
wb-vmd-install. That entry is confined to the build bundle, and is
the only wb-vmd with the install rules (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves.). The same
instance:
- installs macOS;
- runs the provisioning boot and the boots of the second stage;
- exits when its part of the build ends.
The install reads only the restore image at the fixed path
<data>/images/macos-restore.ipsw.
wb-downloadfetches it from Apple’s catalog.wb-hostdchecks its hash before it startswb-vmd-install(S17-03-downloadsS17-03-downloads: DownloadsHow wb-download fetches what an image build needs from the internet.).wb-vmd-installchecks the path again itself (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves.).
A build that seals its image deletes the restore image.
The build bundle
Section titled “The build bundle”Each build starts with a new, empty build bundle. Before it starts
wb-vmd-install, wb-hostd:
- deletes what an earlier build left there, without following symbolic links;
- creates the bundle directory.
When wb-vmd-install exits during a build, the build fails.
wb-hostd deletes the build bundle (S15-04-guest-adminS15-04-guest-admin: The Guest Admin UserHow the host keeps the password of the guest admin user wbadmin, from the image build to each VM's first contact., “The build’s SSH session”), and nothing restarts.
Taking the sealed image
Section titled “Taking the sealed image”wb-hostd treats what is in the build bundle as written by a possibly
compromised wb-vmd (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves.). It takes a sealed image only
after wb-launcher reports that wb-vmd-install has exited. No
process of the build can then still change the bundle.
It takes the system disk and the auxiliary storage, each at its fixed name in the bundle. For each one it:
lstats the name, and requires a regular file withst_nlink1;- opens it with
O_NOFOLLOW; - requires that
fstaton the descriptor gives the samest_devandst_ino, aswb-diskfmtchecks its file (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.); - clones it into
<data>/images/from that checked descriptor, withfclonefileatandCLONE_NOFOLLOW, and never acts on the path again.
It then deletes the build bundle, without following symbolic links.
Any other result fails the build, and wb-hostd logs the rule
build-bundle-not-regular.
A clone of a stored image from <data>/images/ into a VM bundle uses
the same identity check (“Storage and distribution” below, and
S06-03-image-updatesS06-03-image-updates: Image UpdatesHow a VM gets a new image's system disk while its data disk and project users stay, and the guest admin password of each VM.). It clones from the checked descriptor with
CLONE_NOFOLLOW.
Provisioning stages
Section titled “Provisioning stages”The first stage is the provisioning boot.
- The first boot sets the macOS provisioning options. They are new in
macOS 27, so
wb image buildruns on a macOS 27 host. - The options create the user
wbadmin, and turn Remote Login on. They get the guest past Setup Assistant with no clicks. - One SSH session as
wbadmininstallswb-guestdas a root LaunchDaemon, writes cron’s and at’s allow files, and nothing else. - That session runs on the build VM’s own file-handle network, through the host’s userspace stack. Only the host and the build guest can join that network. The channel therefore authenticates the guest.
- A session that doesn’t complete fails the build.
The second stage goes over the host-guest socket to wb-guestd:
- At first contact, before any other request,
wbadmin’s password is rotated from the build’s password to the image’s.wb-guestadminwrites the image’s password to the store first. Both passwords reachwb-guestdon a connection of their own, andsysadminctlon standard input. The build fails if the rotation fails. - The build turns Remote Login and automatic login off.
- The build takes
wbadminout of every group, disables it, and deletes its keychains. - The base layer is installed through
wb-guestd(S06-16-base-layerS06-16-base-layer: The Base LayerWhat the base layer holds, how the image build installs Apple's Command Line Tools from a package the host fetched, and the toolchain user that named images and project layers install as.). wb-guestdinstallswb-guestrootand its LaunchDaemon from the guest tools disk (S15-05-admin-pathS15-05-admin-path: The Admin PathHow the person at the host's terminal gets a root shell in their own guest, on a path that no agent, session, or guest process can start or reach., “In the image”).- The image is sealed (“Sealing” below).
That sealed image is the base, the parent of each named image
(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.) and of its own Claude Code layer. The build
clones it into a new build bundle, boots the clone in wb-vmd-layer
in its layer slot (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.), makes the layer, and
seals it again (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”). A build
for a new Claude Code release does only that part.
After the rotation the secure token works, and the host alone can unlock
it. macOS refuses to delete wbadmin, which holds the volume’s only
secure token. The image keeps it as a host-administered account.
The guest admin password
Section titled “The guest admin password”The provisioning options give wbadmin a password, and the build’s
one SSH session needs it. From then on the host keeps that user’s
password in the configured secret store. 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
who may write, fetch, or receive it.
wb-guestadmin(S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves.) generates a password for each build, and writes it to the store. It hands it on pipes to the build’swb-vmd, until the start call returns. It hands it on a pipe towb-build-ssh, which logs in with it and writes it into the session’s standard input forsudo -S(S15-04-guest-adminS15-04-guest-admin: The Guest Admin UserHow the host keeps the password of the guest admin user wbadmin, from the image build to each VM's first contact.).- Provisioning options for a session VM are refused. The refusal is logged with its rule.
- The password is never in arguments. It is never written to disk outside the store, and never in a log, a gRPC message, or an audit record.
- The guest gets it only in the provisioning options through the
build’s
wb-vmd, in the build’s SSH session, at the login and onsudo -S’s standard input, and at the rotation onsysadminctl’s standard input.
No guest disk mounts
Section titled “No guest disk mounts”The host never mounts a guest disk to build an image
(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.). wb-guestd provisions through named
operations instead. Each runs one fixed task, never an arbitrary
command as root, and takes secrets on standard input, not arguments.
Every clone of an image starts with the same per-machine keys. So
sealing deletes the SSH host keys (/etc/ssh/ssh_host_*_key). The
local Kerberos realm (LKDC) of wbadmin is also the same in every
clone.
An image is never updated in place. A newer restore image rebuilds every layer, and a new Claude Code release only the Claude Code layer.
Guest confinement
Section titled “Guest confinement”The build’s SSH session writes cron.allow and at.allow with root
only, since TCC lets only a process with Full Disk Access write them.
wb-guestd checks them (S13-01-process-hardeningS13-01-process-hardening: Layer 1: Process Hardening (v1)How wb-guestd hardens every process it starts for a project user, and how it stops and kills a project user's processes., “Cron and at”). The
base image includes the Network Extension of 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.,
approved during the build, once spike X14-flow-attributionX14-flow-attribution: Guest flow attributionA Network Extension transparent proxy in a macOS guest (S13-guest-confinement): can it be approved during the image build without MDM? allows it.
Terminfo
Section titled “Terminfo”Sessions get the host’s TERM, or xterm-256color when the image has no entry for it (S16-03-around-the-streamS16-03-around-the-stream: Around the StreamWhat wb writes to the terminal around the filtered stream, the terminal environment the guest gets, and how guest text in wb's other output is escaped., “Terminfo”). The image describes it with a terminfo database that the
build compiles into /usr/local/share/terminfo. Root owns it, and no
other user can write to it.
The source is misc/terminfo.src from an ncurses release tarball, 6.6
or later, pinned by version and SHA-256. The build appends two alias
entries:
xterm-ghostty|Ghostty terminal emulator, use=ghostty,xterm-kitty|KovId's TTY, use=kitty,Ghostty sets TERM=xterm-ghostty, and kitty sets TERM=xterm-kitty.
But ncurses names their entries ghostty (first in release 6.6) and
kitty (first in release 6.2). The aliases point those names at
ncurses’ reviewed entries.
The guest compiles the database, because the host never writes the guest disk, and a root-owned file has to be created in the guest. 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? (I28I28 (closed): X17-image-build: Unattended image buildX17-image-build (added to S11-verification-and-spikes in #14)):
- The host checks the tarball’s SHA-256.
- It sends the source to a named
wb-guestdoperation. - The operation compiles it with
tic -xfrom the same ncurses release, and installs the result as root. - It returns success, or a failure with a text.
A failure fails the build. The host cuts that text to 1024 bytes, and
escapes it wherever it shows it. It does the same for the version
wb-guestd reports (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., “Version skew”).
wb-guestd sets TERMINFO_DIRS=/usr/local/share/terminfo: for
project users. macOS’s ncurses also falls back to
/usr/share/terminfo without the empty last entry. The empty entry
keeps that fallback explicit. Which programs can read which entries is
in S16-03-around-the-streamS16-03-around-the-stream: Around the StreamWhat wb writes to the terminal around the filtered stream, the terminal environment the guest gets, and how guest text in wb's other output is escaped., “macOS’s ncurses”.
Sealing
Section titled “Sealing”Before an image is usable, wb-guestd scans it as root, before any
project code has run. The host parses no guest filesystem
(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.). Any finding fails the build:
- anything that looks like a secret, such as keychain items, tokens in
dotfiles, SSH keys and shell history, and
/etc/kcpassword(SEC04-no-guest-secretsSEC04-no-guest-secrets: No secrets in the guestThis includes the model credential.); - an enabled account in the
adminorwheelgroup, other than root and the system accounts macOS ships in it. Membership is checked withdsmemberutil checkmembership, which sees bothGroupMembershipandGroupMembers(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?); - any sudoers entry beyond macOS’s own (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?);
- a non-system account, except
wbadminwhen it meets the conditions below (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?); - Remote Login (
com.openssh.sshdenabled or loaded, or a listener on TCP port 22), screen sharing or remote management, and automatic login (SEC04-no-guest-secretsSEC04-no-guest-secrets: No secrets in the guestThis includes the model credential., SEC05-default-denySEC05-default-deny: Default-deny egress, enforced on the hostOnly allowlisted hostnames are reachable.); - an
~/.ssh/authorized_keysof any user, root included; - a
cron.alloworat.allowthat isn’t a regular file owned by root holdingrootonly (S13-01-process-hardeningS13-01-process-hardening: Layer 1: Process Hardening (v1)How wb-guestd hardens every process it starts for a project user, and how it stops and kills a project user's processes., “Cron and at”); - a change to
sshd_config, or a file insshd_config.dthat macOS doesn’t ship, and SSH host keys left in/etc/ssh; - files outside
/Usersowned by a non-system user ID, other than the temporary folders ofwbadmin; - a toolchain user, or a file of it, outside S06-16-base-layerS06-16-base-layer: The Base LayerWhat the base layer holds, how the image build installs Apple's Command Line Tools from a package the host fetched, and the toolchain user that named images and project layers install as., “At sealing”, and a Wraith Box CA (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., “TLS during a recipe build”);
- launchd jobs outside an allowlist: what macOS ships (
com.apple.*andamsdstat.plistin/Library/LaunchDaemons),wb-guestd’s andwb-guestroot’s (S15-05-admin-pathS15-05-admin-path: The Admin PathHow the person at the host's terminal gets a root shell in their own guest, on a path that no agent, session, or guest process can start or reach.), and, in an image with the Xcode step only, the three jobs 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. names, by label, with the program rule 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. gives.
So every admin account the build creates is disabled or removed at sealing.
The wbadmin exception
Section titled “The wbadmin exception”The sealing scan accepts wbadmin only if all of these hold:
- It is the volume’s only crypto user:
diskutil apfs listCryptoUserslists one. - Its
AuthenticationAuthorityhas;SecureToken;. - It is disabled, hidden (
IsHidden), and without a shell. - It is in no groups but
staff,everyone,localaccounts,_lpoperator,com.apple.sharepoint.group.*, andcom.apple.access_disabled. The last is the grouppwpolicyadds when it disables an account. - Its
~/Library/LaunchAgentsis empty. - Its
~/Library/Keychainsis empty.
The seal manifest
Section titled “The seal manifest”When the scan passes, wb-guestd writes the seal manifest, and
wb-hostd keeps its SHA-256 (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 comparison”).
The base’s seal writes one too. A named image’s build compares the
image with the manifest of its parent.
Storage and distribution
Section titled “Storage and distribution”Images are stored locally. They are cloned copy-on-write into VM bundles: APFS clones on macOS (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.). Sharing images between machines as OCI artifacts in a registry is a later addition.
Decisions
Section titled “Decisions”A separate wb-vmd-install
Section titled “A separate wb-vmd-install”Only the wb-vmd started as wb-vmd-install has the install rules,
and it is confined to the build bundle.
Provision through wb-guestd, never a mounted disk
Section titled “Provision through wb-guestd, never a mounted disk”- Why: an unprivileged host process can’t create a root-owned file on a guest disk, so launchd refuses anything the host would write there. Root on the host is ruled out by SEC12-least-privilegeSEC12-least-privilege: Least privilege on the hostNo root or administrator rights at run time and no extra host user accounts..
- Decided: 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?.
Compile terminfo in the guest from ncurses
Section titled “Compile terminfo in the guest from ncurses”- Why: the aliases use ncurses’ reviewed entries.
- Rejected: a terminfo source from an emulator, which the image doesn’t ship. Kitty’s is GPL-3.0 (S10-tech-stackS10-tech-stack: Technology ChoicesFix languages, libraries, packaging, and repository layout, with the reason for each choice.).
- Rejected: macOS’s own
tic(ncurses 6.0). On the raw 6.6terminfo.srcit stops witherror writingatscrt. Limited to the entries above, it stops atkitty. - Decided: I83I83 (closed): Guest terminfo for the host TERM passed into the sessionS05-cli ("Terminal stream", #81) passes the host's TERM into the guest session, because Claude Code picks its sequences from it..
Status: Draft