C09 - Guest and Sessions
Purpose: The test cases for what a project user can reach inside
the guest, wb-guestd’s update and the guest clock, the shared
toolchain prefix, the guest admin password, and the session lifecycle.
Verifies: 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”), 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. (“Creation”), 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. (“Mounting the data volume”), S06-06-devices-and-warm-startS06-06-devices-and-warm-start: Devices, Warm Start and TimeA VM's devices and resources, saving and restoring its state, and how the guest clock follows the host. (“Time and sleep”), S06-08-projects-and-sessionsS06-08-projects-and-sessions: Projects and Sessions Inside a VMHow projects map onto guest users and sessions onto worktrees, and how Claude Code runs in the guest. (“Removing a home”), 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., S06-10-leftover-processesS06-10-leftover-processes: Leftover ProcessesThe results of the kill of a project user, how wb-hostd accepts them, and what it does when processes are left., S06-12-guest-agentS06-12-guest-agent: Guest AgentWhat wb-guestd, the service in the guest, does for the host, and how it updates itself. (“Update at start”), 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., 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., 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.
Fuzzing
Section titled “Fuzzing”- The toolchain manifest parser in
wb-hostd, and the name check inwb-guestd(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”). - The parser of
diskutil info -plistinwb-guestd,FuzzParseInfoininternal/platform/guestmount: an accepted report has a UUID and a device of the formdisk<N>s<N>, and a report without an encryption property reads as encrypted (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., “The mount”). - The checks of a kill result in
wb-hostd,FuzzKillResultininternal/hostd/kills: a KillUser answer or a cleanup record of any bytes is taken only for a kill ID sent for its project in the VM generation, with a result and count in their bounds, and a record out of bounds is never acknowledged (S06-10-leftover-processesS06-10-leftover-processes: Leftover ProcessesThe results of the kill of a project user, how wb-hostd accepts them, and what it does when processes are left., “Acceptance”). - The parser of
dscl -plistrecords inwb-guestd,FuzzDirectoryRecordininternal/platform/guestusers: guest root can write the values, and an accepted record keeps the bounds on its values and their count (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., “Creation”). - The parser of a cleanup record file in
wb-guestd,FuzzCleanupRecordFileininternal/guestd/cleanup: guest root can write the records’ directory, and an accepted record has a kill ID other than 0, a project ID of its form and a count of at most 1001, and formats back to the same bytes (S06-10-leftover-processesS06-10-leftover-processes: Leftover ProcessesThe results of the kill of a project user, how wb-hostd accepts them, and what it does when processes are left., “Kill IDs and records”). - The checks of a session report in
wb-hostd,FuzzGuestSessionReportininternal/hostd/sessions: a report of any bytes is accepted only for its session, with an exit code from 0 to 255 or a signal from 1 to 64. A refusal’s message has no guest text (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., “Ending”).
Conformance
Section titled “Conformance”From the guest
Section titled “From the guest”- Read or change policy, credentials, or the audit log from the guest.
- As a project user outside the session profile, bind a free vsock port
below 1024, on the wildcard CID and on the guest’s own, and see
EACCES. Bindwb-guestd’s port the same two ways while it runs, and see the bind refused. The rule for ports below 1024 isn’t in Apple’s developer documentation, only in the XNU source (bsd/kern/vsock_domain.c,VSOCK_PORT_RESERVED,proc_suser), so each guest image is checked. Inconformance/guestsock:TestFreeLowPortsNeedRootandTestGuestdPortRefused. - As root, connect to
wb-guestd’s port on the guest’s own CID in a loop for 30 s. Seewb-guestdstill hold the port (a root bind getsEADDRINUSE), and its log hold at most oneguestd-accept-failedorguestd-peer-not-hostrecord per 10 s (S04-02-vm-providerS04-02-vm-provider: VM Provider and StreamsHow wb-vmd hands guest connections and the NIC endpoint to other processes, the fixed device set of a VM, and where wb-proxyd takes a stream's identity from., “Guest ports below 1024”, I115I115 (closed): S04-architecture, S06-vm-lifecycle: wb-guestd vsock listener under connect floods and bind failuresFollow-up from the security review of #114 (the X27-vsock-confinement result, #101).). Meanwhile, connect from the host, and see the host still reach the port and each of its connections logged as served from CID 2. Inconformance/guestsock:TestSelfCIDFlood, with the host side run by hand. TestGuestdPortRefusedandTestSelfCIDFloodskip unlessWB_CONFORMANCE_I615=1is set. I615I615 (open): Guest kernel panic found in X31-admin-channel: narrow it down and gate the conformance casesFound in #448 (X31-admin-channel), by chance. holds them back until it says which guests they are safe on (T22-guest-kernel-panicT22-guest-kernel-panic: A guest process can panic its own VM's kernelIn X31-admin-channel a guest-side operation by an unprivileged user in a macOS 27.2 guest stopped the guest's kernel, and the guest rebooted.).- Kill
wb-guestdwithSIGKILL, and see launchd start it again and it hold its port again. - Inside a session, open an
AF_VSOCKsocket, and seeEPERM(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?). - As root, run
sudo -l -Ufor each project user, and see no rules listed, and noadminorwheelgroup in itsid(S06-vm-lifecycleS06-vm-lifecycle: VM Lifecycle, Images and the Guest AgentHow guest images are built, how VMs are kept warm, how projects and sessions map onto guests, and what wb-guestd does., 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?).
Update at start and the clock
Section titled “Update at start and the clock”Spec: S06-12-guest-agentS06-12-guest-agent: Guest AgentWhat wb-guestd, the service in the guest, does for the host, and how it updates itself. (“Update at start”), S06-06-devices-and-warm-startS06-06-devices-and-warm-start: Devices, Warm Start and TimeA VM's devices and resources, saving and restoring its state, and how the guest clock follows the host. (“Step or slew”).
- As root, step the clock 5 s forward and back, and see the wall clock
follow at once. Slew it by 0.5 s each way, and see the kernel hold
the slew. In
conformance/guestclock:TestStepandTestSlew. - Boot a guest whose installed
wb-guestdhas another build version than its tools disk. See the hello answer with the disk’s version, and the wait for the disk and the update logged. Boot it again, and seetools disk is currentlogged. - In a boot without the tools disk, attach a disk image whose volume is
named
wb-guest-toolsas a user other than root, and startwb-guestdagain. See the mount refused withguestd-tools-untrustedand nothing installed. Attach it as root, read-only, and seewb-guestdinstall its programs and run the new one under the same process ID.
Data volume
Section titled “Data volume”Spec: 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. (“Mounting the data volume”), SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another., SEC11-root-gains-nothingSEC11-root-gains-nothing: Guest root is not a privilegeFull control of the guest grants no control over enforcement, secrets, or policy., NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it..
Unit tests in internal/guestd, with a fake diskutil, statfs and
lstat:
TestMountFresh: the mount of a fresh volume unmounts it from/Volumes, mounts it at/private/var/wbhomes, and claims its root, with the owner it had before the claim logged.TestMountWaitsForVolume: the guest mounts a volume that appears after 5 s.TestMountVolumeNeverAppears: a volume that never appears is refused withdata-volume-missingafter 30 s.TestMountRefusals: an encrypted volume, one whose report doesn’t say, a failed unmount or mount, a mount point that is a link or owned by a user, and a failed claim are each refused with their rule, logged with what was found.TestMountAgain: a second mount, also after a restart ofwb-guestd, only checks the volume it finds mounted, and refuses another UUID withdata-mount-volume.TestMountAgainFirstMount: withoutfirst_mountthe root isn’t claimed. With it, a volume found mounted is claimed once its mount passes the check, and not when it fails.TestMountDeadline: the whole mount runs under a deadline of 40 s, between the 30 s wait and the host’s 45 s, and a deadline that passes ends the wait withdata-volume-missing.TestCheck: after a mount, the check before a session refuses withdata-mount-flagswithout each ofnosuid,nodev,nobrowseor ownership, withdata-mount-volumefor another volume or none, withdata-volume-encryptedfor an encrypted one, and withdata-mount-rootfor a root that is a link, a file, or has another owner or mode.TestCheckPending: before any mount the check refuses withdata-mount-pending.TestSameMount: the mountfstatfsreports of an opened root passes only when it is the one the last check passed. Another mount, a check that failed since, or no check isdata-mount-volume.TestMountDataRPC:MountDataanswers each refusal withFAILED_PRECONDITIONand oneErrorInfowhose reason is the rule, and a UUID of the wrong form withINVALID_ARGUMENTandguestd-mount-invalid.TestMountRulesListed: the rules ofwb-guestdare the listwb-hostdtakes.
The host side is under “Guest link” in C11-host-daemonsC11-host-daemons: Host Daemons, Audit, and DisksThe test cases for the host daemons' own checks: wb-vmd's device set and slots, the image build bundle, supervision, the accounting and event channels, the daemon log pipes, the audit writer, free space, and the data….
In the guest, after wb-hostd had wb-guestd mount the volume, in
conformance/datamount:
- As a standard user and as root, see the mount carry every flag, the
volume reported unencrypted, and the check pass (
TestMounted). - As root, copy the test binary onto the volume as a setuid-root file,
run it as the standard user, and see it report that user’s UID as
its effective UID. The same copy in
/private/var/tmpmust report root, or the test fails (TestSetuidIgnored). - As root, remount the volume with
mount -u -o suid, and see the check refuse withdata-mount-flags. Setnosuidback, and see it pass (TestRemountRefused). - Boot a VM with a fresh data disk, and see the volume mounted by its
UUID and its root before the claim logged. Stop and start it, and
see it mounted again without a claim. Run
wb vm reset-data, and see the next boot claim the root again.
Project users
Section titled “Project users”Spec: 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. (“Creation”), SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another., SEC11-root-gains-nothingSEC11-root-gains-nothing: Guest root is not a privilegeFull control of the guest grants no control over enforcement, secrets, or policy., SEC12-least-privilegeSEC12-least-privilege: Least privilege on the hostNo root or administrator rights at run time and no extra host user accounts..
Unit tests in internal/guestd/users, with a fake directory and volume
root:
TestNewUser: a new user gets its group, then its user record, then its home, withGeneratedUIDfirst and the IDs last in each record.TestSameUser: a user whose records and home match is kept, with nothing written.TestRecreate: a home on the data disk with no records, as after a new system disk, gets its records back, and the home stays as it is.TestPartialRecord,TestMissingGroupRecord,TestMissingHome: a record that stopped halfway, a missing group record and a missing home are completed.TestConflicts,TestConflictNewUser: a record with another value, an alias, anAuthenticationAuthority, a shadow hash, a member or a nested group is refused withproject-user-conflict. So is another record that holds one of the user’s names, IDs orGeneratedUIDs, in any case, or nests the project group. Each is refused before any write and logged with the attribute, and the request’s other users are still made.TestHomes,TestHomeOfKeptUser: a home owned by another UID isproject-home-other-owner. A link, a file, another group, another mode or a special bit isproject-home-invalid.TestIDsOwnEntry: a UID or GID that owns another entry of the volume’s root isproject-ids-own-entry.TestRootCheckRefused: a root that fails the caller’s check refuses each user with the check’s rule, and a request without a check withproject-home-root, before any write.TestRootRefused,TestDirectoryFailures,TestLockedRecord,TestDeadline: a root that can’t be read, a failed list, read or write, a write the directory didn’t keep, a home path macOS locked once the IDs were set, and a request past its deadline each refuse with their rule.TestInvalidUser,TestCheckRequest: a value outside the allocation isproject-user-request-invalidwith nothing read, and a request with no user, too many, a UID or name twice, or aGeneratedUIDthat two users share is refused as a whole.
On the guest’s own file system, in internal/guestd/users:
TestRealHomeMade (mode 700 under a umask of 0), TestRealHomeLink,
TestRealHomeMode and TestRealIDsOwnEntry. In
internal/platform/guestusers, TestRootMkdirUndone sees a home whose
fchown failed removed again, and TestRootEntriesLongName sees a
name of 300 bytes listed. Over a socket pair, in internal/guestd:
TestEnsureUsersRPC, TestEnsureUsersOneBadUser (one invalid user
refused, the others made), TestEnsureUsersBeforeMount (refused with
the data mount check’s rule), TestEnsureUsersRootOnOtherMount
(data-mount-volume) and TestEnsureUsersRequestRefused, each read by
wb-hostd’s own check of the answer.
With the work VM, TestC09GuestUsersVM in cmd/wb-hostd (needs-vm,
under a test data root as TestC11HostdVM): give the data disk two project users in state.db, and
see wb-hostd log both as ensured on a new link, after a reboot, and
after the system disk is cloned anew while the data disk stays. It logs
how long the guest took for each request, which the 50 s deadline for
128 users is judged by.
As root in the guest, after wb-hostd had wb-guestd make at least two
project users, in conformance/guestusers:
TestNoSudo,TestNotAdmin,TestNoSecureToken: no project user has asudorule,adminmembership or a secure token.TestIDs: each user’sidshows its own UID and GID, and no group but its own,everyoneandlocalaccounts. Each record has the password*and noAuthenticationAuthorityor shadow hash.TestHomes,TestHomesApart: each home is a directory of mode 700 owned by its user, and one project user can’t list another’s.TestEnsureKeepsAndRefuses:EnsureUsers’ code, with every write refused, keeps each user, and refuses one with anotherGeneratedUIDwithproject-user-conflict.
Locking, killing and removing
Section titled “Locking, killing and removing”Spec: S06-08-projects-and-sessionsS06-08-projects-and-sessions: Projects and Sessions Inside a VMHow projects map onto guest users and sessions onto worktrees, and how Claude Code runs in the guest. (“Removing a home”), S06-10-leftover-processesS06-10-leftover-processes: Leftover ProcessesThe results of the kill of a project user, how wb-hostd accepts them, and what it does when processes are left., 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”, “When the link drops”, “Per-user launchd services”), SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another., SEC11-root-gains-nothingSEC11-root-gains-nothing: Guest root is not a privilegeFull control of the guest grants no control over enforcement, secrets, or policy..
Unit tests of the loops in internal/guestd/procs, with a fake process
table and clock:
TestKillClean,TestKillBootsOutWithNoProcess: a kill ends every process whose UID or real UID is the user’s, and no other, and runslaunchctl bootoutat least once.TestKillRespawn: a KeepAlive agent that launchd starts again is ended in a later round.TestKillRoundBound,TestKillTimeBound,TestKillCap: a process that survives is reported after 10 rounds or 30 seconds, logged withproject-user-kill-incomplete, at most 5 names escaped and cut, and a count capped at 1001.TestKillListError,TestKillCanceled,TestKillZombie: a process table that can’t be read counts as 1001 left, a canceled kill as at least one, and a zombie as none.TestStopAll,TestStopAllAgain: the stop loop stops every running process of the project range, and not root’s ornobody’s. It records the ones it stopped itself, apart from those already stopped.TestStopAllBound,TestStopAllListError: a process that stays running is logged withproject-users-stop-incomplete.TestStopAllExclude: while a removal empties a home, the stop loop leaves a process whose UID and real UID are both that user’s running, and stops it again once the removal releases it.
Unit tests of the cleanup records in internal/guestd/cleanup:
TestFormatParse, TestParseRefuses and TestFileName (one format,
canonical numbers, the bounds), TestStoreWriteList (one record per
user, the newest), TestStoreListSkips (a bad file is logged and
skipped), TestStoreOpenRefuses (a records’ directory that isn’t a directory of
root’s with mode 700 and no special bit, or opens through a link, is
refused with cleanup-record-dir) and TestStoreWriteFails.
Unit tests of the lock and the removal in internal/guestd/users, with
a fake directory, volume root, kill loop and child:
TestLocks,TestLocksKill: every user is locked at start, only an unlock of a known user unlocks it, and a kill locks it again. An unlock while the kill runs is refused withproject-user-kill-running.TestRemoveKnown: a removal kills, empties the home as the user, removes it, gives the record the shell/usr/bin/false, then disables and hides it, in that order. The record stays,EnsureUsersrefuses the user afterwards, and a second removal answers removed.TestRemoveAfterRestart,TestRemoveAfterDiskSwap: with nothing known, a record with the request’s IDs and home, or with no record a home the UID owns, is removed.TestRemoveRefuses,TestRemoveRootCheck: a request out of form, a known user of another project, a record or home of another UID, a failed directory read and a root off the data mount are refused before any kill or child, each logged with its rule. A known user of another project stays unlocked.TestRemoveHomeChecks: a home that is a link, a file or another UID’s starts no child, and retires nothing.TestRemoveProcessesLeft: with processes left, no child starts and nothing else changes.TestRemoveChild,TestRemoveChildDeadline: a child that didn’t start, ended on a signal, or ran past its 15 seconds, refuses withproject-home-child-failedand retires nothing. A home the child couldn’t empty stays, logged withproject-home-left.TestRemoveRetireFails,TestRemoveRunning: a failed retirement refuses, andEnsureUsersrefuses the half-retired record. A removal,EnsureUsers, kill or unlock of a user whose removal runs is refused withproject-user-removal-running.
On the guest’s own file system, in internal/platform/guestusers:
TestRootRmdir, TestDirWriteRead, TestDirNames, TestDirReadRefuses
(a link, a FIFO, a directory or a file over the cap isn’t read),
TestRootOpenDirLink, TestEmptyHomeRefuses and TestEmptyHomeArgs
(the first pass runs chmod only on a directory the user closed). In
internal/platform/guestprocs, TestListsOwnProcess and TestSignal
(a PID below 2, or one whose start time changed, gets no signal).
Over a socket pair, in internal/guestd, each read by wb-hostd’s own
check of the answer where it has one:
TestUnlockUserRPC: an unknown user stays locked withproject-user-unknown.TestKillUserRPC,TestKillUserLeft: the answer and the cleanup record hold the kill’s result.TestKillUserRefused: a kill ID of 0, a project ID out of form, a UID out of range (guestd-kill-invalid) and a known user of another project (project-user-unknown) are refused before any kill.TestKillUserDuringRemoval: a kill and an unlock of a user whose removal runs are refused withproject-user-removal-running, and the kill boots nothing out.TestKillUserRecordRefused: a record that can’t be kept, before the data mount or in a directory guest root left owned by a user, fails the call with its rule.TestRemoveUserRPC,TestRemoveUserNotRemoved: a removal answers removed, or processes left, or refused with the data mount check’s rule.TestLinkDropStops: the end of the host’s connection runs the stop loop.
As root in the guest, in conformance/guestusers, each only with its
variable naming the UID of a project user it may end:
TestKillUser(WB_CONFORMANCE_KILL_UID): one kill ends a KeepAlive LaunchAgent, a detached process with SIGHUP ignored and a process in its own session. None is back 5 seconds later, andlaunchctl printof the user’s domain fails or doesn’t name the agent.TestRemoveUser(WB_CONFORMANCE_REMOVE_UID): a removal removes the home with a file the user made in it, and a directory the user set to mode 000 with a file in it, keeps the record, andpwpolicy -authentication-allowedreports the account disabled.
With the work VM (needs-vm, needs-host), by hand:
kill -9ofwb-guestdwith a session running: the new process stops the project users’ processes before it serves.- A link drop with a session running stops its processes, and one stopped before the drop is recorded as such.
wb project rmof a project whose home holds a file owned by root: the home stays, logged withproject-home-left, and the removal is answered removed.- A system disk swap with a removed project: the retired record is gone with the old system disk, and the home is still gone.
The toolchain prefix
Section titled “The toolchain prefix”Spec: 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”, 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)?.
- As a project user, replace a link in the prefix’s
bin, write to a binary in itsCellar, and runbrew install, and see each refused. - As root, check that every file in the prefix belongs to the toolchain user and to its own group, that the group has no other members, and that others can’t write any of them.
- Hand
wb-hostdmanifests with atap, acask, asystemline,brew "--force",brew "--HEAD",brew "jq.rb", a name with a/, a name over the length cap, and too many lines. See each refused with the line and the rule. Send the same names towb-guestddirectly, and see it refuse them too. - Declare a formula with no bottle for the guest, and one whose dependency has none, and see the session refused with the formula’s name before anything is installed.
- Remove the formula data snapshot, and see the reconcile refused.
- With a session of project A running, reconcile project B, whose
formulae share dependencies with A’s, and see every
opt/*link of A’s formulae point where it did before (I180I180 (open): X20-shared-homebrew: verify the untested toolchain prefix conditions in a guestX20-shared-homebrew (#31, PR #178) answered "yes, with conditions" for one Homebrew prefix owned by the toolchain user.). - Run A’s tools with the session
PATH, which leaves out the prefix’s sharedbin. - See Homebrew’s temporary and cache files only in the toolchain user’s mode-700 home.
The guest admin password
Section titled “The guest admin password”At first contact, with a data disk whose project homes hold a LaunchAgent and a login item:
- see the rotation finish before
wb-hostdsends the time and beforewb-guestdlists its sessions, and nothing from the data disk run before it; - see
wbadmindisabled again with a usable secure token, and the image password refused bydscl . -authonly; - drop the link during a rotation, and see the disk marked “rotation unknown” and every session start refused with its rule.
Session lifecycle
Section titled “Session lifecycle”With a wb-guestd that the test drives as guest root. Each case checks
the audit entry with its rule.
The session helper, unit tests in internal/guestd/shell on darwin and
linux. They run unprivileged, with no user switch and a test program in
place of zsh:
- See the helper lead the POSIX session, and the program lead its own process group, which is the PTY’s foreground group, with the PTY as its controlling terminal.
- Write a
Ctrl-Cbyte and see the program getSIGINT. Resize and seeSIGWINCHwith the new size. - Have the program stop itself, and see one stopped frame. Resume it and see it run on.
- Exit with 0 and with 3, and kill the program with
SIGKILL. See each reported, interactive and not, with the output before the exit frame. - Hang up an interactive shell and see the program get
SIGHUP. With a program that ignores it, see it killed after the hangup delay, and another user’s process in the same POSIX session logged and left. - Without a PTY, see standard input end with EOF, a closed standard
output give
EPIPE, and standard error on its own channel. - Kill the helper and see
session-helper-goneand the session killed. With a helper failure and a kill that leaves processes, seeshell-hangup-killand the helper’s rule in the log. - Exit cleanly after a child left the session with
setsid, and see the child logged withshell-process-outside-sessionand left. - Send a report out of form, one after the exit and an exit code of
256, and see
session-helper-reportand the session killed. See the reader refuse a continued report first, two stops in a row, and a stop past 1024. - Have a helper report the exit and run on, and see it hung up and
killed before the exit frame. With a kill that leaves processes, see
the kill logged
incompleteand ashell-hangup-killfailure in place of the exit frame. - Make the process table unreadable during the kill and see the kill
retry. With a table that never reads, see the kill logged
incompleteand ashell-hangup-killfailure. - Start a shell while a stop loop runs and see it wait for the loop. See a new connection leave a running stop loop to its bounds.
- Resume a shell and see its processes dropped from the stop loop’s set.
- Send each refused start: an id, size, user or environment out of form, an unknown, privileged or locked user, a data mount that fails its check, an id in use, and a helper that doesn’t start. See each refused with its rule and nothing started.
- See the program’s exact environment, and the replica owned by the user with mode 0600.
- Send a host
TERMthe guest’s terminfo database has, one it lacks, and malformed ones such as../x, and see the first kept and the others replaced byxterm-256color, logged withshell-term-unknownorshell-term-malformed(TestGuestTerm,TestEnvironmentTermFallback). - End the stream on a live connection and see a hangup. End it with the link and see the shell left to the stop loop.
FuzzHelperReport: arbitrary report bytes never give an exit code outside 0 to 255, a signal outside 1 to 64, or a report after the exit.FuzzGuestTerm: an arbitraryTERMis kept only as a well-formed name with an entry, and becomesxterm-256colorotherwise.
Debug shells 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… (S06-08-projects-and-sessionsS06-08-projects-and-sessions: Projects and Sessions Inside a VMHow projects map onto guest users and sessions onto worktrees, and how Claude Code runs in the guest., “Debug shells 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…”), unit tests of wb-hostd in internal/hostd/shells,
internal/hostd/hostservice and internal/hostd/guestconn, with a fake
guest:
- Open a shell, run it to its exit, and see
wbget the opened message and the exit, and the project user unlocked, then locked and killed once (TestShellOpenAndExit). Closewband see the hangup and the kill (TestShellClientGone,TestRelayClientClose). - Send an open out of form, for an unknown project, before the data
mount, refused by the session start check, for a stopping VM, past 64
shells and in refusing mode, and see each refused with its rule
(
TestShellStartInvalid,TestShellProjectUnknown,TestShellMountPending,TestShellSessionRefused,TestShellVMStopping,TestShellSessionCap,TestShellRefusingMode). - Send guest frames out of form, an exit code of 256, signals 0 and 65,
standard error that wasn’t asked for, a frame over its cap, a frame
after the exit, and repeated stops, and see each end the shell with
its rule (
TestCheckFrame,TestRelayFailures,TestRelayAfterExit,TestRelayStoppedRepeat,FuzzGuestShellFrame). - Have a guest ignore the hangup, and see the stream cancelled after
the hangup delay and its margin (
TestRelayHangupTimeout). - Drop the link, and see the shell lost and its user killed on the next
link only (
TestRelayLost,TestLostKillsOnNextLink,TestLostKillRetried). - Stall one
wb, and see another shell of the VM run to its end (TestStalledClientDoesNotStallOthers). - Run
wb vm stopwith a shell open, and see it refused naming the shell (TestVMStopNamesShells). - Fail the unlock, and see the shell refused and its user locked and
killed (
TestShellUnlockFailed). Hold the guest’s stream past its open time, and see the shell end withguest-shell-refused(TestShellOpenHeld). Open a second project’s shell in the isolated VM, and see it refused withisolated-slot-taken(TestShellIsolatedTaken,TestRegisterIsolatedTaken). Endwb’s stream while its shell waits, and seeshell-client-goneand nothing unlocked (TestShellClientGoneWaiting). - End a shell while another of its project waits, so the kill is
skipped, and see the waiting shell’s release send it, and no kill
without a skip (
TestReleaseSendsSkippedKill,TestReleaseWithoutSkipSendsNone). Lose a shell after a relink, and see its user killed at once (TestLostAfterRelinkKillsNow), or by the release of a waiting shell of its project (TestReleaseSendsLostKillAfterRelink). Fail a kill’s send, and see it sent on the next link (TestKillNotSentRetriedOnNewLink). End a shell after close, and see no kill (TestNoKillAfterClose). - Repeat stops, and see the first logged and the count logged at the
end (
TestRelayStoppedRepeatsCounted). Send frames after the exit, and see them dropped and the stream cancelled past 16 (TestRelayAfterLastFlood). Closewbon the exit, and see no hangup (TestRelayClientCloseOnExit). Fail a send to the guest, and see the shell hung up (TestRelayGuestSendFails).
wb shell itself, in internal/projectcmd with a fake ShellService:
see it refuse an argument with exit 2, an unregistered project, a host
without terminal support and a charset other than UTF-8 with 255, and
print wb-hostd’s refusal with its rule (TestParseShell,
TestShellNotRegistered, TestShellTerminalUnsupported,
TestShellCharsetRefused, TestShellHostdRefusal). Send SIGINT
while the open waits, and see the call cancelled and wb exit with 255
and shell-open-signal (TestShellSignalDuringOpen).
TestC09ShellVM in cmd/wb-hostd, needs-vm, opens
real shells in the work VM through wb-hostd, piped, for two projects
it adds. It checks:
- the project user, and that it can run the installed
wb-guestd; - the exact environment, with the host’s
TERMandLANGunchanged and the six trust variables of S09-08-guest-trustS09-08-guest-trust: Guest TrustHow wb-guestd makes the guest's clients trust the VM's CAs.; - the login shell’s
PATH, which the guest’spath_helperbuilds: it keeps/usr/bin:/bin:/usr/sbin:/sbin, and each entry that exists, or the nearest existing ancestor of one that doesn’t, is owned by root and not writable by the project user (SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another.); exit 3gives 3 andkill -9 $$gives 137;- 8 MiB of piped input to a program that doesn’t read it;
lsof the other project user’s home fails withPermission denied, andsudo -n truefails;echo 'echo hi; exit 4' | wb shellprintshiand gives 4;yesinto a reader that closes after one line, ashead -1does, ends promptly with the shell’s status;wb vm stopis refused, naming the shell, while a shell is open.
The checks that need a terminal are attended, run by hand with
wb shell --project P in the work VM. They check:
- the terminal’s title and the label line;
- in a terminal whose
TERMthe guest has no entry for, such as Ghostty’sxterm-ghostty,echo $TERMshowsxterm-256colorandclearclears the screen (I474I474 (closed): wb shell: the host's TERM has no terminfo in the guest (xterm-ghostty)wb shell passes the host's TERM to the guest unchanged (#471, S06-09-session-lifecycle).); ttynames a PTY, andps -o sess,pgid,uid -p $$shows the shell as its session’s leader, as the project user;- after a window resize,
stty sizeshows the new size; - Ctrl-C ends
sleep 100and leaves the shell; - Ctrl-Z stops
sleep 100, andfgresumes it; suspend -fin the guest shell gives back the host’s prompt, andfgon the host brings the guest shell back, through the guest’s stopped frame. A login zsh refusessuspendwithout-f;- a
sleep 1000that ignores the hangup and one in its own session, both started beforeexit, and no process of the project user left after the shell ends. macOS has nosetsidcommand, so Perl starts both:perl -e '$SIG{HUP} = "IGNORE"; exec "sleep", "1000"' &andperl -MPOSIX -e 'fork and exit; POSIX::setsid() or die "setsid: $!"; exec "sleep", "1000"'. Thenohupcheck waits on I475I475 (open): Guest sessions: nohup fails with "can't detach from console"In a wb shell (and so in a wb claude session, which uses the same session helper), the guest's nohup fails:, because macOSnohupfails in the session helper’s session; - the second conformance case of C10-terminalC10-terminal: TerminalThe test cases for the terminal filter in wb, which stands between the guest's output and the host terminal., in a real terminal.
Agent sessions in wb-hostd, unit tests in internal/hostd/sessions
and internal/hostd/hostservice (session_unix_test.go), with a fake
guest. Each checks the session’s record in state.db and the audit
entry with its rule:
TestSessionOpenToEnded: open a session while the data mount is pending, and see a waiting message and the record starting. Then see it opened, the record running, the agent’s output, and the record ended with exit code 0 once the report is in. See the report acknowledged after that, and the project user killed.TestSessionRefusedandTestSessionFlagNamesArrival: send an open out of form, past each bound, for an unknown project, and with--learn,--ephemeraland--isolatedof a project in the work VM. See each refused with its rule, nothing registered or unlocked, and each flag’s refusal name when it comes.TestSessionAdmissionRefused: see a session refused past 64 sessions and shells of a VM, in an isolated VM another project has, and in a VM run with processes left. See a refusal after the record exists end the session as a failed start.TestSessionParallel: run two sessions of one project, and see the project user killed once, after the second ends.TestSessionClientClose: send a hangup frame, and close the stream. See the guest get the hangup, the record go to ending, and to ended by the report.TestSessionReportFailures: report an exit code of 256, signals 0 and 65, a push thatreceive-packdidn’t confirm, and a failed push. See each end as a failure with its rule, sowbexits with 255.TestSessionRelayGuestStopsReadingandTestSessionRelayAckBounded: have the guest stop reading. See wb’s closed stream still hang up the session, and the stream cancelled at the ending deadline. See the ack give up after 10 seconds and cancel the stream.TestVMStopNamesSessions: runwb vm stopwith a session running, and see it refused withvm-live-sessions. The refusal gives the session’s ID, its state, and the way it ends.TestPlaceRefusedWithSession: runwb project placewith a session running, and see it refused withproject-place-has-session, naming the session.FuzzGuestSessionReport, as in “Fuzzing”.
Exit codes and lost sessions:
- Report an exit code of 256 and a signal number of 0 and of 65, and
see
wbexit with 255. - Drop the link, then list a running session of the other VM, an ended session, a malformed id, an unknown id and a running session of an earlier VM generation. See “end” for each, and no session of the other VM change state.
- Drop the link and leave a running session out of the list, and see
it lost and
wbexit with 255. - Send a list of 65 entries, and see it refused and the connection closed.
- Drop the link again and again, and see at most 20 connections to the VM in a minute.
Reports:
- List one id both as a held session and as a report, and see the list refused.
- Send a report for another VM’s session and for an unknown id, and see “end” and the report gone from the guest’s directory.
- Send a report again for an ended session, and see it acknowledged with no change.
- Drop the link right after a session ends, before its report reaches the host, and see the session end with that report, not as lost.
The WIP commit and push:
- Drop the link while the WIP commit runs, bring it back, and see the stopped commit killed, the commit run again and the session end normally.
- Report a WIP push that never reached
receive-pack, and see a failed push, withwbexiting 255 and the summary’s count taken fromlanding.git. - Never report a WIP commit, and see the session end as a failure at
its deadline, with
wbexiting 255 and the summary naming the worktree’s path andwb shell.
Commands and pushes around a session:
- Run
wb vm stopandwb vm suspendwith a running session, and see both refused with the session named. - During recovery, push to the recovering session’s branch and to another session’s, and see only the first accepted.
- Push to an ended session’s branch, and to a discarded one’s, and see both refused.
- Close the terminal while a child of
claudehas left the session withsetsidand another session of the project runs, and see the child logged as a survivor (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.). With no other session, see it killed.
Leftover processes
Section titled “Leftover processes”Spec: S06-10-leftover-processesS06-10-leftover-processes: Leftover ProcessesThe results of the kill of a project user, how wb-hostd accepts them, and what it does when processes are left., S06-11-reconnect-and-recoveryS06-11-reconnect-and-recovery: Reconnect, Loss and RecoveryWhat happens when the host-guest link drops, when a session is lost, and how a lost session's work is recovered or discarded. (“Answers to cleanup records”), SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another., SEC11-root-gains-nothingSEC11-root-gains-nothing: Guest root is not a privilegeFull control of the guest grants no control over enforcement, secrets, or policy..
Unit tests of the host side in internal/hostd/kills, with a fake
clock:
TestKillCleanAccepted: a clean result of a kill that was sent is accepted and logged.TestKillAcceptanceRules: a project ID of the wrong form, a kill ID never sent, one sent for another project, in another VM or in an older generation are each dropped with their rule, and the kill is still pending.TestKillReplyForAnotherKill: an answer that names another kill than its request is dropped.TestKillAnotherGeneration: a kill of one generation takes no result in the next.TestKillLateResultandTestKillMissingResult: a result after the 7-minute deadline is dropped, and a kill with no result counts as processes left at its deadline.TestKillProcessesLeft: a result of processes left refuses sessions, learn mode and saves, logs the count capped at “more than 1000”, and asks for a cold boot. Only a new generation clears it.TestKillColdStopandTestKillColdStopAfterDeadline: a cold stop closes the pending kills with its cause, and a kill past its deadline before it still counts as processes left.TestKillBeginOldGenerationandTestKillIDs: no kill is sent to a generation that a newer one or a cold stop ended, and kill IDs are never 0 and never repeat.TestKillResultNewerGeneration: a result for a generation newer than the slot’s is dropped, and leaves the slot’s kills pending.TestKillResultAgain: a result again for a kill is acknowledged and logged with the verdict kept, and one of processes left still counts.TestListRefusedandTestListAnswers: a reconnect list with more records than project users, or two with one kill ID, is refused whole. Each other record gets “acknowledged” or “end”.
In internal/guestlink, TestCheckKill and TestCountLabel: an answer
or record out of the contract’s bounds is refused with
guest-users-reply-invalid.
In internal/hostd/guestconn, with a fake wb-guestd:
TestFirstConnectionKills: the first connection of a VM generation sends a kill for every project user, each with its own ID, and session starts wait for them. A reconnect sends none again.TestProcessesLeftRefusesSessions: a result of processes left refuses session starts and saves until the next generation.TestKillUser: a session of a project is refused while a kill of its user is pending.KillUserreturnsErrKillNotSentfor a canceled call, after a cold stop, and for a generation that doesn’t run.
In internal/hostd/vm, TestOnEnded: each run’s end reaches the kill
tracker with its cause.
The admin path
Section titled “The admin path”wb vm adminwithout a terminal, and with a wrong answer to its question, is refused withadmin-no-terminalandadmin-not-confirmed, andwb-hostdopens no connection.- With a session running, and before first contact’s rotation has
ended,
wb-hostdrefuses withadmin-sessionsandadmin-before-rotation, and writes each refusal as a 5019 event. - With the isolated slot lent to the build VM,
wb vm admin isolatedis refused withadmin-slot-lent, andwb-vmd-installis never asked for the admin port. - A session start racing
wb vm admineither runs and makes it refuse withadmin-sessions, or comes after the mark and is refused withvm-admin-used. The two never run together. - After the mark, a session start, a debug shell and
wb vm suspendare refused withvm-admin-used, also after awb-hostdcrash between the mark and the connection. - When writing the mark or its 5019 event fails, no connection opens.
When the connection fails after the mark, with
peer-version-mismatchor awb-guestrootthat doesn’t answer, the mark stays. - While the shell is open, the idle period doesn’t end, a lend of the
isolated slot waits, and
wb vm stopandwb vm suspendfrom another terminal are refused withvm-admin-open. - After the shell ends, the idle period’s end and a lend stop the marked VM cold, and no saved state is written. A start of a marked VM with a saved state placed in the test deletes it, replaces the system disk, boots cold, and clears the mark.
- A host stop or a
wb-hostdcrash during an open shell leaves the mark. The nextwb-hostdstart writes the missing end event with the cause unknown. wb vm adminprints the warning of T19-pasted-login-codeT19-pasted-login-code: A login code pasted into a guestClaude Code in the guest can print a real authorize URL with its PKCE challenge. before the shell opens.- An ask for
wb-guestroot’s port from anything but the admin service is refused withadmin-port-unrequested. - In a guest, a project user can’t bind
wb-guestroot’s port while it restarts. The case of a connection from the guest’s own CID waits on I615I615 (open): Guest kernel panic found in X31-admin-channel: narrow it down and gate the conformance casesFound in #448 (X31-admin-channel), by chance., because that connect panicked macOS 27.2 guests (X31-admin-channelX31-admin-channel: A root shell from a second guest daemonCan wb-guestroot, a root LaunchDaemon apart from wb-guestd on a vsock port of its own below 1024, give the host a root shell on a PTY while wb-guestd is dead, stopped or restarting?). The root shell opens whilewb-guestdis stopped. - Each use writes the two 5019 events, the end event with its cause.
Status: Draft