S06-08 - Projects and Sessions Inside a VM
Purpose: How projects map onto guest users and sessions onto worktrees, and how Claude Code runs in the guest.
Design
Section titled “Design”Guest users
Section titled “Guest users”Each project gets a dedicated guest user account, created by
wb-guestd. Its home on the data disk holds:
- the project clone;
- Claude Code state (FR13-claude-stateFR13-claude-state: Claude Code state per projectClaude Code's conversation history, and the state it keeps only in the guest, persist per project, so --resume/--continue work within a project.);
- tool caches.
Guest users can’t read each other’s homes (SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another.). No host user accounts are created (SEC12-least-privilegeSEC12-least-privilege: Least privilege on the hostNo root or administrator rights at run time and no extra host user accounts.).
A home is mode 700, under the data volume’s mount point (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.). Its path is set when the user is created, and never changes, because macOS refuses to change it in the record (X08-data-diskX08-data-disk: Data disk for homesGuest user homes on a second disk, surviving a system-disk replacement.).
Removing a home
Section titled “Removing a home”A home is removed when its project is removed (wb project rm), or
when an ephemeral user’s session ends. wb-hostd sends RemoveUser
with the project and the user’s UID, GID and home. wb-guestd takes it
only for one of these:
- the user it made or checked with that project since it started;
- after a restart, a record with that name, UID, primary group and home;
- after a system disk swap, with no record, a home whose owner is that UID.
With no record and no home it answers that the user is removed. A
request for a known user of another project is refused with
project-user-unknown. One removal of a user runs at a time, and
another is refused with project-user-removal-running.
Then wb-guestd:
- locks the user (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., “Locked users”) and runs
the kill loop (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., “Per-user launchd
services”). With processes left, it answers how many, changes
nothing else, and
wb-hostdasks again later; - removes the entries of the home in child processes that run as
that user, in its own group only, for at most 15 seconds. So it never
follows a link the user left with root’s rights. The first gives the
user every right on each of its directories, so a directory it set
to mode 000 doesn’t hide its entries, and the second removes them. A
child that didn’t start, ran past its deadline, or ended on a signal
refuses the removal with
project-home-child-failed, and the record stays as it was. The stop loop at a link drop leaves the processes of a user under removal alone, so it doesn’t stop that child; - removes the home directory itself;
- retires the record: the shell
/usr/bin/falsefirst, thenpwpolicy -disableuserand hidden from the login window. A step that fails refuses the removal, andwb-hostdasks again. Because the shell goes first,EnsureUsersrefuses a record that a failed step left half retired.
What that user can’t remove stays, such as a file guest root left
there. wb-guestd logs it with project-home-left and still answers
that the user is removed. It stays in a directory no later user gets,
because the user’s IDs are never reused (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.,
“Allocation”).
The record stays, locked and disabled, by design. The user’s IDs are
never reused (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., “Allocation”), and the next system
disk starts the directory without it. This doesn’t depend on whether
root can delete the record. In 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? sysadminctl -deleteUser
left it, and in X08-data-diskX08-data-disk: Data disk for homesGuest user homes on a second disk, surviving a system-disk replacement. (item 11) opendirectoryd refused its
deletion through dscl (I138I138 (closed): S06-vm-lifecycle: wb-guestd can't delete a macOS user record (eDSPermissionError)S06-vm-lifecycle says wb-guestd creates, locks and removes project users.). In the needs-vm run of PR441PR441 (merged): feat(guestd): lock, kill loop and removal of project userswb-guestd locks every project user in memory at start, kills a user's processes with a bounded loop, keeps a cleanup record per kill, stops project processes when the link drops and at start, and removes a project…, root’s
dscl . -delete through sudo removed one. A removal of a retired user runs the same steps, and answers that
it is removed again. EnsureUsers refuses a retired user, because its
shell differs.
So each removed project leaves one user record and one group record in the VM’s local directory, which grows by those two for the life of the system disk. A system disk swap starts the directory again from the image.
Standard accounts
Section titled “Standard accounts”A project user is a standard account:
- outside the
adminandwheelgroups; - with no sudoers rule.
Guest root can bind the host-guest socket port of wb-guestd. So a
project user must not reach root through sudo
(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?).
Packages come from the toolchain prefix, which only wb-guestd writes
(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., “Toolchain prefix”, and 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)?).
Worktree per session
Section titled “Worktree per session”Each session gets its own git worktree of the project clone, at
<home>/sessions/<session-id> in the project user’s home. So parallel
sessions in one project don’t collide (FR05-parallel-sessionsFR05-parallel-sessions: Parallel sessionsSeveral sessions can run at once, in the same project and across projects.).
Per-session build outputs, such as Xcode DerivedData, are kept inside the worktree.
Conversation history
Section titled “Conversation history”Claude Code keeps its conversations per working directory, under
~/.claude/projects/<directory>. <directory> is the path, with each
character other than a letter or digit replaced by -. claude --continue resumes “the most recent conversation in the current
directory” (claude --help, Claude Code 2.1.289).
Each session has a new worktree path. So before it starts claude,
wb-guestd, running as the project user:
- makes that directory for the new worktree;
- makes it a symbolic link to one directory per project,
~/.claude/projects/wb-project.
--continue and --resume then find the conversations of the
project’s earlier sessions (FR13-claude-stateFR13-claude-state: Claude Code state per projectClaude Code's conversation history, and the state it keeps only in the guest, persist per project, so --resume/--continue work within a project.).
The link is made as the project user (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., “As the project user”). So wb-guestd never follows a link the project user
made with root’s rights.
wb discard removes the session’s link with its worktree. It leaves
the per-project directory.
Claude Code in the guest
Section titled “Claude Code in the guest”S14-claude-in-guestS14-claude-in-guest: Claude Code in the GuestHow Claude Code gets into the guest image, which of the user's Claude Code configuration goes with it, how it starts, and the agent interface that keeps Claude Code's specifics in one place (V1-02-claude-only). specifies its install, the carry-in of the user’s configuration, and its permission mode (X01-model-credentialX01-model-credential: Model credential via the proxyDoes Claude Code work with a placeholder credential while wb-proxyd injects the real one, for each supported authentication mode, including token refresh?, B60-model-credentialB60-model-credential: Can Claude Code in the guest hold only a placeholder while the proxy adds the real subscription token?Yes, for a long-lived token from claude setup-token.).
The image sets the Claude Code version, and the updater is off in the
guest. A new Claude Code version needs a new image. Building an image
for a new Claude Code version must be cheap next to a full wb image build (I220I220 (closed): Cheap image rebuild for a new Claude Code version- Which stage a Claude Code-only rebuild starts from (a sealed earlier stage, a clone of the image before sealing, or another layer), and how that fits sealing and "never updated in place".).
The environment
Section titled “The environment”wb-guestd starts claude with these variables in its environment
allowlist:
- the model credential’s placeholder (S09-05-credentialsS09-05-credentials: CredentialsHow credentials are stored and bound to requests, and how the model credential reaches the model API without entering the guest., “Model credential”). It is in
CLAUDE_CODE_OAUTH_TOKENfor a long-lived token, or inANTHROPIC_API_KEYfor an API key; CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1. Claude Code’s documentation says it turns off updates, telemetry, error reporting and feature flag fetching (B45-claude-in-guestB45-claude-in-guest: How does Claude Code run in the guest, and which of the user's settings go with it?Carry in an allowlist of the user's Claude Code configuration with secrets and hooks removed, start in bypassPermissions mode, and pin Claude Code in the image with every in-guest update path off., “Evidence”);DISABLE_UPDATES=1, which blocks every update path,claude updateincluded (I45I45 (closed): S14 (new): Claude Code in the guest and the agent interface (V1-02-claude-only)No spec says how Claude Code itself runs in the guest.).
The variables aren’t the control
Section titled “The variables aren’t the control”The variables are meant to keep Claude Code from asking for the hosts and paths that the model API profile leaves out. That is assumed, and C06-model-apiC06-model-api: Model APIThe test cases for the model credential: its placeholder, the scan for the placeholder in whole requests, what is injected on the model API, the event log, and Claude Code end to end. checks it.
The control is wb-proxyd. It refuses the event log, and every host
outside the profile, whatever the guest sets (S07-11-http-policyS07-11-http-policy: HTTP PolicyThe HTTP rules of inspected hosts, the built-in profiles, and the parts a user can turn off., “model API”).
With the variable set, Claude Code doesn’t fetch feature flags. So it
reaches /api/eval/ only when CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC
is unset, as in the second pass of the C06-model-apiC06-model-api: Model APIThe test cases for the model credential: its placeholder, the scan for the placeholder in whole requests, what is injected on the model API, the event log, and Claude Code end to end. run. The
profile’s allow of /api/eval/ stays, because the variable isn’t the
control.
Plugins
Section titled “Plugins”Plugins from the marketplace are unavailable in the guest in V1V1-initial: Initial versionThe first version: what it delivers, what it leaves out, and the milestones that get there.,
because downloads.claude.ai is outside the profile.
Ephemeral sessions
Section titled “Ephemeral sessions”Ephemeral sessions use a throwaway guest user, removed at session end (FR14-ephemeralFR14-ephemeral: Ephemeral sessionsAn ephemeral mode runs a session with no persisted state.).
Debug shells in V1-M2
Section titled “Debug shells in V1-M2”In V1-M2-walking-skeletonV1-M2-walking-skeleton: Walking skeletonwb-vmd boots a fixture VM bundle in its confined process, wb-guestd answers over vsock, a data disk made on the host holds the homes, and wb shell opens a PTY as a project user, with its output through the terminal fi…, wb shell (S05-03-management-commandsS05-03-management-commands: Management CommandsThe commands of wb other than the agent commands.) is the only session,
and wb-hostd keeps its shells in memory, not in state.db. The
session states of 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. come with wb claude.
Until then:
wb-hostdopens a shell only once the VM’s data mount and the project user are there (Links.CheckSessionStart). It waits up to 3 minutes for a starting VM and refuses a stopping one. Awbthat getsSIGINT,SIGQUIT,SIGTERMorSIGHUPin that wait stops waiting and exits with 255 (shell-open-signal), andwb-hostdlogs the shell withshell-client-gone.- A VM has at most 64 open shells (SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.). The 65th
is refused with
vm-session-cap. - No project is marked shared before S09-03-project-settingsS09-03-project-settings: Project SettingsWhat a project's settings hold, and what a repository's own .wraithbox/ configuration may add. exists.
So while one project has a shell in the isolated VM, another
project’s shell there is refused with
isolated-slot-taken, which names the project (S06-04-vms-and-placementS06-04-vms-and-placement: VMs and PlacementThe work VM and the isolated VM, Xcode in them, and which VM a project's sessions run in., “Isolated slot to itself”). - A shell id has the session id form of S05-04-namingS05-04-naming: NamingHow wb identifies a project, a session and its branch, and how projects are registered, checked, moved and removed..
wbchecks it before it puts the id in the terminal’s title. - Each guest frame is checked against its bounds and built again
before it goes to
wb. A frame out of form ends the shell withguest-shell-frame, an exit status out of range withguest-exit-status, andwbexits with 255. - When
wbgoes,wb-hostdsends the hangup and reads on until the exit. It cancels the guest’s stream 15 seconds later, the hangup delay and a 5 second margin (shell-hangup-timeout). - When the guest link drops, each open shell of the VM ends as lost
(
shell-lost). The next link kills those shells’ project users, and no others. - The end of a project user’s last shell locks the user and kills its
processes (
shell-user-kill). A new shell of that project waits for the kill. So does a failed unlock, as the guest may have unlocked the user. A kill that didn’t reach the guest is sent on the next link. - The guest stream has 10 seconds to open, and the shell fails with
guest-shell-refusedpast that. Frames the guest sends after the shell’s last one are dropped, and past 16 of themwb-hostdcancels the stream (guest-shell-frame). wb vm stopis refused while a shell is open, naming each shell.
wb-hostd writes one log line, with the rule, for each open, end,
loss, refusal, hangup, lock, and kill. Of the guest frames it drops,
it logs the first of each kind, and the count once at the shell’s end.
Decisions
Section titled “Decisions”A new worktree path per session
Section titled “A new worktree path per session”- Rejected: one worktree path for every session. A parallel session, or an ended session that isn’t discarded yet, still holds it.
Status: Draft