S13-01 - Layer 1: Process Hardening (v1)
Purpose: How wb-guestd hardens every process it starts for a project
user, and how it stops and kills a project user’s processes.
Design
Section titled “Design”wb-guestd applies this layer to every process it starts for a project
user.
Project users
Section titled “Project users”Each project has a project user (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.), never root. Project users keep files apart, not network traffic (T11-shared-vm-grantsT11-shared-vm-grants: Projects in one VM share network grantsThe host sees one guest address per VM, and can't tell which project user, session or program opened a connection.).
Limits and environment
Section titled “Limits and environment”RLIMIT_CORE is set to 0. The environment is built from an allowlist
(S09-policy-credentials-auditS09-policy-credentials-audit: Policy, Credentials, Certificates and AuditWhere policy comes from, how secrets are held, how TLS inspection is trusted, and what is recorded.).
A session’s PTY replica belongs to the session’s project user, with mode 0600, before the session helper starts. No other project user can open it.
Work as the project user
Section titled “Work as the project user”Every operation under a project user’s home runs in a child process as
that user, with the session’s environment allowlist. That includes the
worktree, the carry-in, and the WIP commit and push. wb-guestd runs as
root, and never opens a path there (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.).
When the link drops
Section titled “When the link drops”When the host-guest socket drops, wb-guestd stops every process of
every project user in the VM. It repeats that in a loop until none is
left running, so no session runs on without host session control.
The stop loop sends SIGSTOP to every process whose user ID is in the
project users’ range, 10000 to 999,999,999. A new wb-guestd knows no
user yet, so the loop goes by the range. The range
leaves out root, the system accounts and nobody. The loop has the kill
loop’s bounds, at most 10 rounds and 30 seconds (“Per-user launchd
services”). When a check still finds a process running after either
bound, wb-guestd logs it with the rule project-users-stop-incomplete
and the processes left, at most 5 of them plus a count.
When the link comes back, a running loop goes on to its bounds, and a shell start waits until no stop loop runs. Then no new loop starts until that shell’s helper runs and its POSIX session is known. No loop stops a shell that starts after it, and a loop that starts after a shell sees the whole shell.
The loop leaves alone the processes of a user whose home a removal empties at that moment, when both their user IDs are that user’s. Those are the removal’s own children, which run after its kill loop and while the user is locked (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”).
It records which processes were already stopped, such as a claude
stopped with job control. When the link returns:
- It resumes a session only when
wb-hostdanswers “resume”. - It then sends
SIGCONTonly to the processes it stopped itself. - On “finish” or “end” it hangs up or kills the session (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.).
A project user’s processes that it stopped, and that no resumed session holds, stay stopped until that user’s processes are killed.
A new wb-guestd process never takes over the sessions of an earlier
one. A VM with a session is never saved for idleness. A restore then
never has a session to resume.
Locked users
Section titled “Locked users”A locked project user can’t run anything new: while a user is locked,
wb-guestd doesn’t start a process as it, except the child that empties its
home in a removal (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”).
The lock is in wb-guestd’s memory only. Every project user starts
locked, and only UnlockUser, for a session start, unlocks one.
UnlockUser refuses a user wb-guestd hasn’t made or checked since it
started, and one whose kill or removal runs. A kill and a removal lock
the user again. A kill of a user whose removal runs is refused, because
the removal runs its own kill loop. So a new wb-guestd process starts with every user
locked, and fails closed without stored state.
When a session’s client goes
Section titled “When a session’s client goes”A session’s client goes when its terminal closes or wb is killed.
Then:
wb-guestdhangs upclaude.- When
claudehasn’t exited 10 seconds later,wb-guestdsendsSIGKILLto every process in the session’s POSIX session (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., “Session helper”). It sends it only to those whose effective and real user IDs are both the session’s project user. It logs any other process in that POSIX session, and leaves it. A process table it can’t read counts as processes left. The kill repeats while any is left, for at most 10 rounds. When some may still be left after the last round, it logs them with the decisionincomplete, and the host gets the failureshell-hangup-killin place of an exit. - When the project user has no other session in the VM, a lost one included, it then kills every process of that user, in a loop until none remain.
- Otherwise it logs each process of that user that is in no session’s POSIX session, with the rule, and leaves it (S13-02-filesystem-profileS13-02-filesystem-profile: Layer 2: Seatbelt Filesystem Profile (v1)The Seatbelt profile each session's process tree runs under, where it comes from, its exceptions for Xcode builds, and its known gaps., “Known gaps”).
The helper’s exit report comes from the project user’s process, so it
doesn’t end a session by itself. When processes of the session’s POSIX
session still run after it, wb-guestd hangs up and kills them as in
steps 1 and 2, and then sends the exit. When the kill leaves processes
that may still run, the host gets the failure shell-hangup-kill in
place of the exit, as in step 2.
A helper that fails or reports out of form gets the hangup and the kill
of steps 1 and 2, and the host gets the failure with the helper’s rule.
When the kill leaves processes that may still run, the host gets
shell-hangup-kill in its place, and the log keeps the helper’s rule.
The log of step 4 runs at every end of a shell, a clean exit included,
so a child that left the session with setsid is logged.
When a project’s last session ends
Section titled “When a project’s last session ends”wb-hostd ends a project’s last session in the VM, debug shells
included. wb-guestd then:
- locks that project user, so nothing new starts as it;
- kills its processes in a loop until none remain.
A lost session counts as a session here until recovery, wb discard,
wb project rm or its deadline ends it
(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., “Lost”). So recovery can still commit
and push as that user.
Until then the user’s remaining processes stay stopped:
wb-guestdstops them at the link drop.- A new
wb-guestdprocess stops every project user’s processes when it starts, before it serves the host. - On its first connection,
wb-hostdnames the project users that have a lost session in the VM.wb-guestdkills the stopped processes of every other project user, in a loop until none remain.
A stopped VM leaves none.
This holds against a process without guest root only. No process is meant to keep running after its project leaves the VM’s effective policy. None is meant to keep running during another project’s learn-mode session either (S07-17-approvals-and-learningS07-17-approvals-and-learning: Approvals and LearningHow an unknown destination reaches the user as an approval request, what an approval grants, and how learn mode collects names.).
Per-user launchd services
Section titled “Per-user launchd services”launchd starts a project user’s per-user agents and services, such as a
simulator’s, in that user’s launchd domain (user/<uid>). They run
outside every session, where killing the session’s processes doesn’t
reach them.
So wb-guestd repeats the kill loop and launchctl bootout user/<uid>
as one loop, until a check after the bootout finds no process of the
user. It does so wherever it kills every process of a project user:
- at the end of a project’s last session;
- in the kill at the first connection, of the users with no lost session;
- when a user’s last client goes and no session of that user is left.
The loop is bounded: at most 10 rounds and 30 seconds. When a check
still finds a process of the user after either bound, wb-guestd:
- logs the failure with its rule and the processes left, at most 5 of them plus a count (SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter., SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.). It escapes and cuts each name as 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. (“Version skew”) does with guest strings;
- leaves the user locked;
- reports the result to
wb-hostd(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.).
It never boots out a domain where it only stops processes, such as at the link drop. A resumed session then keeps its services.
wb-guestd never runs launchctl print or launchctl asuser against a
locked project user.
Cron and at
Section titled “Cron and at”cron and atrun run as root and start a user’s crontab and at jobs
as that user, outside its launchd domain. So bootout doesn’t reach
them, and neither the disabled account nor its shell stops them.
cron.allow and at.allow in /private/var/at, with root only,
close both schedulers to project users. crontab and at read the
files through /usr/lib/cron, a symbolic link to that directory. With
an allow file there, each ignores its deny file and refuses every user
the file doesn’t name. The image build writes the two files
(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., “Guest confinement”). wb-guestd only checks
them, and never writes or removes a file in that directory.
- Why: TCC protects
/private/var/at. In a macOS 27.2 guest, a root LaunchDaemon, wherewb-guestdruns, could read and list the directory,tabs/andjobs/, but each create there failed withEPERM. A Remote Login session has Full Disk Access, and over SSHsudowrote both files (I599I599 (closed): wb-guestd: can't write /private/var/at/cron.allow in a real macOS guest, so it never serves the hostIn a real macOS 27.2 guest (26B123), wb-guestd at cbbc5ce never serves the host.).
At each start, after its stop loop and before it serves the host,
wb-guestd checks that each allow file:
- is a regular file, opened without following a symbolic link;
- is owned by root, and not writable by group or others;
- holds exactly
rootand a newline.
It then checks that no crontab in tabs/ has a project user’s name,
and no regular file in jobs/ has an owner whose ID is in the project
range. Both checks run before it makes or unlocks any project user.
When one fails, wb-guestd logs it with its rule and exits without
serving the host.
Each round of the kill loop also checks for the user’s jobs, after
the signals and the bootout and before it lists the processes. It
looks for the user’s crontab, /private/var/at/tabs/<name>, and for a
regular file in /private/var/at/jobs that the user owns, which is an
at job.
One found, or a check that fails, counts as a process left, and the
loop logs it with its rule. When no process of the user is left but a
job is found, the loop ends at once: nothing removes the job, so
another round can’t change the result. Otherwise it goes on to its
bounds. Either way it reports the user as not clean (“Per-user
launchd services”).
The start check matches a crontab’s name to a project user without regard to case, as APFS and cron’s lookup of the name do.
wb-guestd follows no symbolic link at a name it checks there. The
paths and the bound on the entries it reads are in code, in
internal/platform/guestsched.
This holds against a process without guest root only, as the rest of this layer does.
Status: Draft