S06-01 - Image Layers and the Toolchain Prefix
Purpose: The layers of a guest image, and the toolchain prefix that project layers install into.
Design
Section titled “Design”Layers
Section titled “Layers”A guest image has four layers:
- 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.). - Named image, optional: a recipe run on a clone of the base, such as the
built-in
homebrewrecipe 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.). - 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).
- 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-guestdinstalls 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.).
The Claude Code layer
Section titled “The Claude Code layer”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.
- 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. - 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”.
- It boots the clone in
wb-vmd-layer, in thelayerslot, 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 contactwbadmin’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”). wb-guestdinstalls 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 managedCLAUDE.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”).- 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-hostdtakes it from the build bundle as “Taking the sealed image” says.
Only the layer
Section titled “Only the layer”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:
- the restore image entry’s macOS version and build (S17-04-restore-and-releaseS17-04-restore-and-release: Restore Image and ReleaseThe steps by which wb-download and wb-hostd fetch and check a macOS restore image and a Claude Code release., “The entry”);
- the Wraith Box build version of the bundle that built it;
- the version of the Command Line Tools (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).);
- for a named image, the hash of its 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., “Provenance”);
- for an image with Xcode, Xcode’s version and build and the SHA-256 of each simulator runtime’s disk image (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., “What the build records”).
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”).
Parents
Section titled “Parents”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”).
Derivation
Section titled “Derivation”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.
Toolchain prefix
Section titled “Toolchain prefix”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:
- through
sudo -ufrom root (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.); - by setting the child’s user and group IDs itself
(
syscall.Credentialin Go), with the toolchain group as the only supplementary group. The implementation may prefer this, because thenwb-guestdalone sets the environment.
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").).
Who may write
Section titled “Who may write”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.
The manifest is data
Section titled “The manifest is data”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.
The install
Section titled “The install”wb-guestdresolves the whole runtime closure of the names over the formula data snapshot, as the toolchain user:brew deps --formula -n --union -- <names>.- It checks every name in the closure against the same rules.
- 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.
Bottles only
Section titled “Bottles only”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.
The environment
Section titled “The environment”wb-guestd builds the toolchain user’s
environment from an allowlist:
HOME, and the working directory in its home;- umask 022;
PATHwith the prefix’sbinand 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_HINTSandHOMEBREW_FORBID_PACKAGES_FROM_PATHS=1;HOMEBREW_TEMPandHOMEBREW_CACHEin 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.
A reconcile only adds
Section titled “A reconcile only adds”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:
- The built-in
homebrewrecipe writes a snapshot of Homebrew’s formula API into the toolchain user’s cache (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.). HOMEBREW_NO_AUTO_UPDATEkeeps that snapshot.
Then nothing installed is outdated, and a reconcile only adds kegs.
The session’s PATH
Section titled “The session’s PATH”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.
Conflicts
Section titled “Conflicts”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.).
A new system disk
Section titled “A new system disk”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