Skip to content

S06-01 - Image Layers and the Toolchain Prefix

Purpose: The layers of a guest image, and the toolchain prefix that project layers install into.

A guest image has four layers:

  1. Base: macOS installed from an Apple restore image, plus wb-guestd, Apple’s Command Line Tools and the empty toolchain prefix, and nothing from a third party (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.).
  2. Named image, optional: a recipe run on a clone of the base, such as the built-in homebrew recipe that adds Homebrew (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.). Full Xcode is only in a named image, from the host’s Xcode (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.).
  3. Claude Code layer: Claude Code (S14-01-installS14-01-install: InstallHow the image build downloads Claude Code on the host, checks it, and installs it in the guest image, and which version a guest runs.), the top layer of the sealed image (“The Claude Code layer” below).
  4. Project layer: the formulae the project declares (FR07-toolchain-manifestFR07-toolchain-manifest: Declared toolchainA project's toolchain is declared host-side (on macOS guests, a Brewfile) and reconciled automatically before a session starts.). wb-guestd installs them as the toolchain user into the toolchain prefix, before the session starts (“Toolchain prefix” below).

The image doesn’t contain a Wraith Box CA. wb-guestd installs the VM’s CAs at runtime in the guest trust files. On Linux and Windows guests it also installs them in the system store (S09-08-guest-trustS09-08-guest-trust: Guest TrustHow wb-guestd makes the guest's clients trust the VM's CAs.).

Claude Code releases often, and the image sets its version (S14-01-installS14-01-install: InstallHow the image build downloads Claude Code on the host, checks it, and installs it in the guest image, and which version a guest runs., “Version”). So Claude Code is in a layer of its own, and a new release rebuilds only that layer.

  1. A build seals the image below the Claude Code layer first, as “Sealing” in 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. says. It keeps that sealed image in <data>/images/ as the layer’s parent.
  2. It clones the parent into a new 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”.
  3. It boots the clone in wb-vmd-layer, in the layer slot, which has no install rules, refuses provisioning options, and gives the VM no network device (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.). At first contact wbadmin’s password is rotated from the parent’s password to the new image’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., “One password per VM”).
  4. wb-guestd installs the checked Claude Code binary through its named operation (S14-01-installS14-01-install: InstallHow the image build downloads Claude Code on the host, checks it, and installs it in the guest image, and which version a guest runs., “Into the image”). The operation also installs the managed CLAUDE.md (S14-04-commands-and-endpointsS14-04-commands-and-endpoints: Commands and EndpointsWhich permission mode Claude Code runs in, the commands that don't work in a guest, the guest instructions that explain the guest's limits to Claude Code, and the endpoints Claude Code in the guest may reach., “Guest instructions”).
  5. The clone is sealed again, with the same scan, before any project code runs (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., “Sealing”). wb-hostd takes it from the build bundle as “Taking the sealed image” says.

A new Claude Code release repeats steps 2 to 5 from the parent that is already stored. A layer build doesn’t download a restore image, install macOS, or run a provisioning boot.

state.db records, for each parent, what it was built from:

wb image build takes the layer-only path only when every one of them equals the current build’s. Otherwise it builds every layer. So a Wraith Box upgrade rebuilds the parent, and a fix to the base layer is never sealed out. The parent’s wb-guestd is then the host’s own build, which first contact requires (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., “With wb-guestd”).

The current version of the Command Line Tools comes from a catalog run of S17-06-command-line-toolsS17-06-command-line-tools: Command Line ToolsThe steps by which wb-download and wb-hostd fetch and check Apple's Command Line Tools for the base layer (S06-16-base-layer)., which every build does first. It fetches the catalog and a few distribution files, and no package. When it fails, the build fails. When it reports a newer version, the build makes every layer again. That downloads the restore image again, because a seal deletes it (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.).

A layer build never changes its parent, and never changes an image built earlier. It makes a new image. A VM gets it by an update (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., “Updates”).

A session VM never boots a parent, because a parent has no Claude Code and wb-guestd starts Claude Code by its absolute path in the image. wb image use on a parent, and a VM start on one, are refused with image-is-parent. wb image list shows a parent on its own line, marked as a parent, without a Claude Code version.

A full build replaces the parent of the image it builds. The old parent stays while a stored image built on it is left, and is removed with the last one. Its wbadmin item goes with it (S15-03-access-rulesS15-03-access-rules: Access RulesHow each host process gets only the credentials it needs, for only as long as it needs them, and which process may access which item., “Declared access”).

A named image derives from the base, and images don’t chain (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 Claude Code layer is the only exception. It goes on top of the base, and on top of each named image. A new restore image rebuilds the base, every image above it, and their Claude Code layers.

A named image with Xcode is built in two sealed steps. Its Xcode step clones the sealed base and installs Xcode. After its wb-vmd-layer exits, wb-hostd takes the sealed result into a new, empty build bundle as in 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”. The recipe’s own steps then start from it, in wb-vmd-recipe, which has no Xcode flag, and the image they seal is the parent the Claude Code layer clones (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., “Where Xcode comes from”). The Xcode step’s result is never listed as an image. It is part of the named image, not an image of its own, so images still don’t chain.

A guest has one tool prefix, /opt/homebrew on macOS (X20-shared-homebrewX20-shared-homebrew: Homebrew with more than one project userCan each project user in one guest get its declared Brewfile without a Homebrew prefix that another project user can write to (SEC08-proj-isolation)?). The toolchain user, _wbtool, owns it (I144I144 (closed): S06-vm-lifecycle: which user installs the base layer before sealingFrom the security review of PR #141 (X17-image-build, #28), finding 3., 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., “The toolchain user”).

That user:

  • isn’t an admin;
  • has neither a password nor a shell;
  • has a home of mode 700.

Only wb-guestd runs commands as the toolchain user. It does that in one of two ways:

Project users, the agent included, can read and run the prefix. They can’t write to it or install packages. They install language packages into their own home instead.

Who may write the prefix, and that a manifest is names only, keep one project from changing the tools of another (SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another.). The session PATH rule below keeps sessions reproducible, and isn’t a control. Projects still share the prefix’s contents (T15-shared-toolchainT15-shared-toolchain: Projects in one guest share the toolchain prefixEvery project user runs tools from the one prefix that the toolchain user owns (S06-01-image-layers, "Toolchain prefix").).

Every file in the prefix belongs to the toolchain user and to its own group. That group has no other members. Others have no write permission on any of the files.

A Brewfile is Ruby, and brew bundle runs it as the toolchain user. A project could then plant a file in the prefix that every other project runs from. So wb-hostd reads the manifest as a list of formula names.

  • Each line is brew "<name>", a comment, or blank.
  • Each name matches ^[a-z0-9][a-z0-9+._@-]*$, doesn’t end in .rb, and is at most 64 characters long.
  • A manifest has at most 1000 lines and 200 names.

wb-hostd refuses any other manifest, and logs the line and the rule. Examples are a manifest with a tap, a cask, options or system, a name with a /, or a name starting with -. A name with a / is a tap’s formula, so only homebrew/core formulae are allowed.

wb-guestd checks the names against the same rules before it runs anything. It never runs brew bundle, and never hands Homebrew a file a project wrote.

  1. wb-guestd resolves the whole runtime closure of the names over the formula data snapshot, as the toolchain user: brew deps --formula -n --union -- <names>.
  2. It checks every name in the closure against the same rules.
  3. It runs brew install --formula --force-bottle -- <closure>, by argument list, with no shell, in the toolchain user’s home.

Homebrew applies --force-bottle and HOMEBREW_NO_INSTALL_UPGRADE only to the formulae on the command line. So every keg is named there.

Any nonzero exit of a brew command refuses the session. No later step relies on what a failed run left in the prefix.

Before the install, wb-guestd checks the formula data for a bottle for the guest, for every formula in the closure. When one has none, the session is refused with its name, before anything is installed. Nothing is built from source.

When the formula data snapshot is missing or empty, wb-guestd refuses the reconcile, because Homebrew would download new data.

At the start deadline (S06-09-session-lifecycleS06-09-session-lifecycle: Session LifecycleA session's states from wb claude to its summary, how it starts and ends, its deadlines, and when its VM may be saved.), wb-guestd kills the reconcile’s process group.

wb-guestd builds the toolchain user’s environment from an allowlist:

  • HOME, and the working directory in its home;
  • umask 022;
  • PATH with the prefix’s bin and the system folders;
  • HOMEBREW_NO_AUTO_UPDATE, HOMEBREW_NO_INSTALL_UPGRADE, HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK, HOMEBREW_NO_INSTALL_CLEANUP, HOMEBREW_NO_ANALYTICS, HOMEBREW_NO_ENV_HINTS and HOMEBREW_FORBID_PACKAGES_FROM_PATHS=1;
  • HOMEBREW_TEMP and HOMEBREW_CACHE in its home;
  • the trust variables of S09-08-guest-trustS09-08-guest-trust: Guest TrustHow wb-guestd makes the guest's clients trust the VM's CAs., with the same constant values project users get, never appended to an inherited value.

It never sets HOMEBREW_DEVELOPER.

Homebrew upgrades an outdated dependency of a formula it installs, whatever HOMEBREW_NO_INSTALL_UPGRADE says, unless that dependency is named on the command line. “The install” makes sure it is.

The formula data keeps dependencies, such as openssl@3, from moving under a running session:

Then nothing installed is outdated, and a reconcile only adds kegs.

Which version a name like python3 runs in the prefix’s shared bin depends on every project’s formulae.

The session’s PATH has opt/<formula>/bin, and Python’s libexec/bin, for each formula of the image’s recipe (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 the project’s manifest. It doesn’t have the shared bin. A project can add the shared bin back, so this is for reproducible sessions only.

wb-guestd sets NPM_CONFIG_PREFIX to a folder in the home, because npm -g writes to the prefix by default.

Homebrew can refuse a formula because a conflicting one is installed, such as mysql and mariadb. The reconcile then fails. wb refuses the session, names both formulae, and points to --isolated (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.).

The prefix is on the system disk. So a new system disk loses what project layers added, and the next session start installs it again.

Status: Draft