Skip to content

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.

Each project gets a dedicated guest user account, created by wb-guestd. Its home on the data disk holds:

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

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:

  1. 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-hostd asks again later;
  2. 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;
  3. removes the home directory itself;
  4. retires the record: the shell /usr/bin/false first, then pwpolicy -disableuser and hidden from the login window. A step that fails refuses the removal, and wb-hostd asks again. Because the shell goes first, EnsureUsers refuses 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.

A project user is a standard account:

  • outside the admin and wheel groups;
  • 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)?).

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.

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:

  1. makes that directory for the new worktree;
  2. 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.

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".).

wb-guestd starts claude with these variables in its environment allowlist:

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 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 use a throwaway guest user, removed at session end (FR14-ephemeralFR14-ephemeral: Ephemeral sessionsAn ephemeral mode runs a session with no persisted state.).

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-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.

  • Rejected: one worktree path for every session. A parallel session, or an ended session that isn’t discarded yet, still holds it.

Status: Draft