Skip to content

S06-02 - Image Build

Purpose: How wb image build makes a guest image: the build VM, its two provisioning stages, terminfo, sealing, and storage.

host: trusted wb-guestadmin build password wb-build-ssh one SSH session via wb-netd wb-download restore image wb-hostd checks the hash wb-vmd-install install, boots sealed image <data>/images/ build guest: untrusted 1. provisioning boot wbadmin, Remote Login on wb-guestd, cron.allow, at.allow 2. through wb-guestd password rotated, Remote Login off wbadmin disabled, base layer sealing scan SSH host-guest socket starts checked clone the host never mounts a guest disk
The image build. wb-download fetches the restore image, and wb-hostd checks its hash before it starts wb-vmd-install, which installs macOS and runs the build's boots. In the provisioning boot, the provisioning options create wbadmin and turn Remote Login on, and wb-build-ssh's one SSH session, on a connection wb-netd opens for the build VM only, with the password from wb-guestadmin, installs wb-guestd and writes cron's and at's allow files. Everything after goes through wb-guestd over the host-guest socket, from the password rotation to the sealing scan. After wb-vmd-install exits, wb-hostd clones the checked disks into the sealed image. The host never mounts a guest disk.

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:

  1. installs macOS;
  2. runs the provisioning boot and the boots of the second stage;
  3. exits when its part of the build ends.

The install reads only the restore image at the fixed path <data>/images/macos-restore.ipsw.

A build that seals its image deletes the restore image.

Each build starts with a new, empty build bundle. Before it starts wb-vmd-install, wb-hostd:

  1. deletes what an earlier build left there, without following symbolic links;
  2. 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.

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:

  1. lstats the name, and requires a regular file with st_nlink 1;
  2. opens it with O_NOFOLLOW;
  3. requires that fstat on the descriptor gives the same st_dev and st_ino, as wb-diskfmt checks 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.);
  4. clones it into <data>/images/ from that checked descriptor, with fclonefileat and CLONE_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.

The first stage is the provisioning boot.

  • The first boot sets the macOS provisioning options. They are new in macOS 27, so wb image build runs 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 wbadmin installs wb-guestd as 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:

  1. At first contact, before any other request, wbadmin’s password is rotated from the build’s password to the image’s. wb-guestadmin writes the image’s password to the store first. Both passwords reach wb-guestd on a connection of their own, and sysadminctl on standard input. The build fails if the rotation fails.
  2. The build turns Remote Login and automatic login off.
  3. The build takes wbadmin out of every group, disables it, and deletes its keychains.
  4. 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.).
  5. wb-guestd installs wb-guestroot and 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”).
  6. 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 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.

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.

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.

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)):

  1. The host checks the tarball’s SHA-256.
  2. It sends the source to a named wb-guestd operation.
  3. The operation compiles it with tic -x from the same ncurses release, and installs the result as root.
  4. 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”.

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:

So every admin account the build creates is disabled or removed at sealing.

The sealing scan accepts wbadmin only if all of these hold:

  • It is the volume’s only crypto user: diskutil apfs listCryptoUsers lists one.
  • Its AuthenticationAuthority has ;SecureToken;.
  • It is disabled, hidden (IsHidden), and without a shell.
  • It is in no groups but staff, everyone, localaccounts, _lpoperator, com.apple.sharepoint.group.*, and com.apple.access_disabled. The last is the group pwpolicy adds when it disables an account.
  • Its ~/Library/LaunchAgents is empty.
  • Its ~/Library/Keychains is empty.

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.

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.

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”

Compile terminfo in the guest from ncurses

Section titled “Compile terminfo in the guest from ncurses”

Status: Draft