Skip to content

The Linux host

Claude Code runs here as systemd user units of the user claude (#319). Its user manager (user@<uid>.service) starts them at boot without a login, because linger is on (loginctl enable-linger claude). Nothing runs as root at runtime; root only does a few one-time steps (below).

Unit Runs Default
sandboxd.service the Docker Sandboxes daemon, sbx daemon start in the foreground enabled
claude-sandbox@<name>.service one sandbox per repository, with its coordinator and workers inside (below) enabled
claude-remote.service the home session, native on the host, for setting up and investigating the host—never for development disabled

The unit files live in systemd/user/; scripts/sandbox/sandboxes.sh setup installs them to ~/.config/systemd/user/. A user unit reads no login profile, so its environment is exactly what it declares. Two things follow:

  1. Setting a variable is not enough. A running process never picks up a changed environment. The unit has to be restarted, which ends the Claude Code session running in it.
  2. ~/.local/bin is on PATH only because the unit says so. claude-remote.service sets PATH=%h/.local/bin:%h/.local/share/mise/shims:…. mise's shims folder gives the session the Node.js and pnpm that a repository's mise.toml declares (#348), ahead of /usr/bin, where Ubuntu's older nodejs lives. dev-doctor's ~/.profile block puts the same two folders first for login shells (SSH, a remote IDE).

The developer tools need no root (#912). On a new host, ./scripts/dev-doctor -Fix, run as claude in a terminal, installs Java 25, Node.js 24, gh, jq and Python 3.13 as global mise defaults, and pipx with mise's Python for pre-commit and semgrep. A tool apt already installed at the required version is left as it is.

The JDK comes from the build (#353). A Gradle repository declares its Java toolchain. Gradle finds that JDK, or provisions it into ~/.gradle/jdks through the foojay resolver declared in settings.gradle.kts; dev-doctor reports both with ./gradlew -q javaToolchains. The system JDK 25 (apt's openjdk-25-jdk, or mise's java@temurin-25) is only what Gradle itself starts on, and what a repository without a wrapper builds with. A sandbox that cannot reach the resolver's download hosts needs the JDK installed on the host instead.

Why the home session is disabled. It is the one process on the host that holds every token: its unit reads the token file whole. The coordinators and workers run in the sandboxes, where no token enters the VM. The owner starts the home session when the host itself needs work, and stops it afterwards:

systemctl --user start claude-remote      # as claude; shows in claude.ai/code as claude:<host>
systemctl --user stop claude-remote

The owner may enable it instead (systemctl --user enable --now claude-remote); then it starts at every boot.

It runs from ~/work, not the home directory (#932). Claude Code never saves trust for the home directory, so Remote Control started there exits with "Workspace not trusted" and the unit restart-loops. sandboxes.sh setup creates ~/work and marks it trusted in ~/.claude.json; no root step is needed. In claude.ai the bridge shows that folder, "work". New sessions start in it.

Tokens

Tokens go into one file owned by claude, ~/.config/claude-dev-doctor/claude-remote.env (mode 0600), the token file. Everything reads that file itself; there is no copy:

  • The home session: its unit names the token file as its EnvironmentFile, which the user manager reads as claude. The unit unsets GITHUB_TOKEN and GH_TOKEN (UnsetEnvironment=, #304), because gh would prefer them to its own login. It unsets ANTHROPIC_API_KEY too: Remote Control refuses API-key auth, and the unit would restart-loop (#319). A value written to the file is staged until systemctl --user restart claude-remote, which needs no root.
  • The sandboxes: their secrets call the token helper ~/.local/lib/claude-sandbox/sbx-token, which reads the file on every refresh (secrets.md). A new value reaches them without a restart.
  • Login shells (SSH, a remote IDE, a claude --bg daemon started from one): a marked block in ~/.profile, written by dev-doctor -Fix, exports the file line by line. It is not sourced as shell code, because a value such as Bearer … holds a space. A new login sees a new value at once. GITHUB_TOKEN and GH_TOKEN are skipped there too; ANTHROPIC_API_KEY is not, since only Remote Control refuses it. In a login shell, gh uses its stored login, and the GitHub MCP server reads GITHUB_PERSONAL_ACCESS_TOKEN.

The home unit takes the token file's lines as its own settings. So a line that configures rather than authenticates changes how the session runs: PATH, PERMISSION_MODE, SHELLOPTS, LD_PRELOAD, and the other reserved names of scripts/linux/service-keys.sh. status.sh and dev-doctor -Only Systemd report such a line by name.

The service keys are what status.sh, rotate.sh and dev-doctor expect in the file and compare with the running home session. They are seven defaults (GITHUB_TOKEN, GITHUB_PERSONAL_ACCESS_TOKEN, AIKIDO_API_KEY, SONATYPE_GUIDE_TOKEN, CONTEXT7_API_KEY, CLAUDE_GITHUB_LOGIN, SBX_GEMINI_API_KEY) plus the names in ~/.config/claude-dev-doctor/service-keys, one per line. Adding one is a name, never a value:

echo CLOUDFLARE_API_TOKEN >>~/.config/claude-dev-doctor/service-keys   # as claude

A service-keys that exists but cannot be read stops set-token.sh and rotate.sh before they change anything.

The user claude has no sudo, so nothing here escalates. The scripts write files the user owns and print the exact sudo command for the owner's one-time steps. "Never escalate" is about the host user; root inside a sandbox's throwaway VM (sbx exec -u root) is allowed (#530).

Usage

Run everything as claude (from another account, sudo -u claude -i), with three exceptions:

  • harden.sh, which the owner runs as root on a new host (below);
  • root-steps.sh, which an admin runs with sudo (below);
  • worktree-base.sh, which runs as the owner of the worktree folder or with sudo.

The other scripts refuse to run as anyone else: the token file lives in claude's home, and only claude reaches its user manager.

# where do things stand?
bash scripts/linux/status.sh

# test every token: validity, scopes, Projects access, token file vs. home session, leftovers
bash scripts/linux/rotate.sh

# replace tokens — all, or the named services (github context7 sonatype aikido)
bash scripts/linux/rotate.sh rotate [github ...]

# store a single variable by hand — hidden input, never on a command line
bash scripts/linux/set-token.sh GITHUB_TOKEN

# login shells: write the ~/.profile block; fill the token file from the running home session
./scripts/dev-doctor -Only Systemd -Fix

# a new token for the home session, if it runs (ends the session in it)
systemctl --user restart claude-remote

# afterwards: revoke replaced GitHub tokens, remove leftovers (asks first)
bash scripts/linux/rotate.sh clean

# the units and the sandboxes: what is installed and running, then install and start everything
bash scripts/sandbox/sandboxes.sh
bash scripts/sandbox/sandboxes.sh setup [--reviewed]

# the shared worktree folder: create it, or make it setgid like /srv/projects
sudo bash scripts/linux/worktree-base.sh /srv/worktrees /srv/projects

# repository chores
bash scripts/tools/create-github-labels.sh
bash scripts/tools/connect-repo-remote.sh <repo-directory>

Run status.sh first when something behaves oddly. It tells the token file apart from what the running home session has, which is exactly the difference a missing restart hides. For the GitHub tokens it also names the account each one acts as. The sessions act as the bot account; a token of another account is reported, and rotate.sh refuses it (token-rotation.md).

Each step dev-doctor cannot take itself is one of these scripts with its parameters, never a list of single shell steps (#333). Its "What to do" section ends with the commands in the order to run them, the root ones marked # root, to copy as one block.

connect-repo-remote.sh stays the owner's. The bot cannot create repositories under the owner's account, so the owner creates the repository, invites the bot, and connects the first checkout.

Two git identities belong here, each with its own @lauper.net address:

  • the user claude commits as Claude Agent (the bot account);
  • the owner, working from their own account on the host, commits as <owner login>.

dev-env:dev-doctor checks that each has a name and an email at gitEmailDomain from .claude/dev-doctor.json, and that GitHub sees the login in CLAUDE_GITHUB_LOGIN. For the user claude that is the bot's login, stored in the token file with set-token.sh CLAUDE_GITHUB_LOGIN.

The owner never runs git in a checkout that claude owns. A .git/config there can name a pager, an editor or a core.fsmonitor command, which git runs as whoever runs git: the owner, or root under sudo. The owner reads such a checkout with plain file tools, and runs git and the root steps in their own clone.

The scripts

Script Does
scripts/linux/status.sh where things stand—the token file vs. the running home session, leftovers of the old system units; run it first when something behaves oddly
scripts/linux/rotate.sh test, replace and clean up tokens (token-rotation.md)
scripts/linux/set-token.sh store a single variable by hand, with hidden input
scripts/linux/claude-intake.sh start an intake session: claude with the intake plugins turned on for that session, here or with --sandbox <name> in a sandbox (plugin sets)
scripts/sandbox/sandboxes.sh the user units and the Docker Sandboxes in systemd/sandboxes.conf—status, or setup as claude: installs and starts everything, prints the pending root steps (below)
scripts/linux/harden.sh hardens a new host, as root, from the owner's own clone: the admin account, Tailscale, claude without sudo, automatic updates, key-only SSH, ufw (below)
scripts/linux/root-steps.sh the one-time root steps, for an admin, from the owner's own clone: prepare and cutover (below)
scripts/linux/worktree-base.sh the shared worktree folder: creates it with the projects folder's group, mode 2775, or sets its setgid bit; as its owner, or with sudo
scripts/sandbox/claude-sandbox.sh start, stop and status of one sandbox and its coordinator session; claude-sandbox@<name>.service runs the copy in ~/.local/lib/claude-sandbox/
scripts/linux/sbx-token the token helper the sbx secrets call; installed in ~/.local/lib/claude-sandbox/ too
scripts/linux/sandbox-root-packages.sh runs as root inside a sandbox (piped in by setup): installs python3-venv and ICU when missing
scripts/sandbox/sandbox-provision.sh runs inside a sandbox (piped in by setup): tools, plugins, workspace trust, cross-session messages, mise and a workspace's mise.toml tools
scripts/tools/create-github-labels.sh repository chore: create the coordination, needs:*, human:*, host-step, issue-type and labs labels in every aise-* repository of OWNER, or in the one named
scripts/tools/connect-repo-remote.sh repository chore, the owner's: connect a checkout under /srv/projects to its GitHub remote and push
scripts/linux/claude-vault-setup.sh the owner's one-time part of syncing the service user's tokens from Bitwarden: sudo bash … <dev-project-id> writes PROJECT_ID into its vault.env, enables linger and runs vault.sh token as that user; idempotent
scripts/linux/lib.sh shared helpers for set-token.sh and rotate.sh—sourced, not run
scripts/linux/service-keys.sh the service keys, the reserved names and how service-keys is read; sourced by lib.sh and status.sh, not run
scripts/linux/github-account.sh the GitHub account and scope check of rotate.sh and status.sh—sourced, not run
scripts/windows/Invoke-RemoteRotate.ps1 runs rotate.sh on the host over SSH (scripts/windows/README.md)

Where tokens live, and why they never go into a file that is committed or synced: secrets.md.

The one-time root steps

Root never runs a file that claude can change (#275, owner decisions r1 and r2). An admin account runs scripts/linux/root-steps.sh from the owner's own clone, after git pull --ff-only brought it to the reviewed main. The script refuses to run from a folder claude can write. It reads no other file of the repository: the drop-in's text is inside it. sandboxes.sh and dev-doctor print the commands while a step is pending, and each step skips what is in place.

sudo bash scripts/linux/root-steps.sh prepare   # (a) any time, harmless
sudo bash scripts/linux/root-steps.sh cutover   # (b) once the user units run

(a) prepare changes nothing that runs:

  • linger for claude, so its user manager and units start at boot;
  • claude into the group kvm, which a sandbox needs. The user units get the group once user@<uid>.service restarts: a reboot, or systemctl restart user@<uid>.service, which stops every unit of claude;
  • the stop window of the user manager: /etc/systemd/system/user@<uid>.service.d/zz-stop-window.conf with TimeoutStopSec=150, then systemctl daemon-reload (below).

(b) cutover removes the old system setup:

  • it disables and stops claude-remote.service, every claude-remote@<name> and claude-daemon.service, and a system sandboxd or claude-sandbox@, should one exist;
  • it removes their unit files and .d/ drop-ins, /etc/claude-remote.env and /usr/local/lib/claude-sandbox, then runs daemon-reload.

It ends every session in those units—possibly the coordinator that asked for it. It refuses while claude's sandboxd.service does not run. It asks before it changes anything: --yes skips the question, and without a terminal it refuses unless given. --force skips the user-unit check. A unit it cannot stop stops the cutover before any file is removed.

A new host: harden it

A provider hands a new host over with root login over SSH on a public address and no service user. scripts/linux/harden.sh (#892) hardens it before anything else runs there. It is the one script that changes how one gets into a host; root-steps.sh prepare stays harmless and is one of its steps. Run it as root, from your own clone at the reviewed main, in a terminal:

sudo bash scripts/linux/harden.sh --admin <owner login> --key <path to your SSH public key>

On a host that has only root, the clone can be the two scripts: copy scripts/linux/harden.sh and scripts/linux/root-steps.sh, with your .pub file, into root's home with scp, then run bash harden.sh --admin <owner login> --key <your key>.pub there. The key is a file, never pasted. In order, each step skipped when already done, it:

  1. creates your admin account in sudo, adds the key to its authorized_keys, and asks for its password with passwd's hidden prompt, because sudo asks for it once password login is off;
  2. installs Tailscale from its signed apt source and runs tailscale up: sign in through the link it prints;
  3. creates the user claude without sudo, and takes it out of sudo, admin and wheel;
  4. installs unattended-upgrades and turns it on in /etc/apt/apt.conf.d/20auto-upgrades;
  5. writes /etc/ssh/sshd_config.d/00-harden.conf: key login only, no password or keyboard-interactive login, no root login. It sorts before cloud-init's 50-cloud-init.conf, and sshd takes the first value it reads. sshd -t tests it before sshd reloads;
  6. once sshd is hardened, turns on ufw for IPv4 and IPv6: incoming denied, allowed on tailscale0, its rules for port 22 (alone, in a list or in a range) or OpenSSH removed;
  7. removes root's Claude Code, the provider's native or global npm install, so that command -v claude as root finds nothing;
  8. runs root-steps.sh prepare (below);
  9. prints every step's check as a table, with whether the host has a /dev/kvm. Without one there are no Docker Sandboxes, and the sessions run natively.

Steps 5 and 6 wait for a key login over Tailscale. Before them the script prints an ssh command with password login turned off and the host's Tailscale address, and asks whether it logged you in from a second terminal and whether sudo -v took your password there: without root login, the admin's sudo is the way in. Without a yes, without a terminal to ask in, or while step 1 is not OK (the admin has no password, say), it skips both and runs the rest. Without a Tailscale sign-in it stops before them. In each case run the same command again once it works. Keep the first session open: changing sshd ends no running session.

A lockout has one way back: the provider's root console in its web panel, which uses neither SSH nor the network filter. A second run changes nothing and only prints the table. What the script finds but leaves for you is a FAIL row: a sudoers rule that gives claude sudo, sudo as its primary group, a ufw rule that lets in more than Tailscale, a claude program it does not know. Root's settings in /root/.claude stay. Then go on as claude below.

A new host: bootstrap as claude

A new host's service user starts with an empty home folder and no credentials, and this repository is private, so nothing in it can be fetched yet. scripts/linux/bootstrap.sh bridges that (#913). A public gist carries a copy of it, and it needs no root.

Before you run it:

  • create a machine account in the Bitwarden web vault with read access to the project that holds this host's tokens (add it, then save), and an access token for it;
  • the project needs at least GITHUB_TOKEN, and SBX_GIT_IDENTITY (Name <email>) for the commit identity.

Then, logged in as claude, in a terminal (it reads the token with hidden input and refuses without one):

curl -fsSL https://api.github.com/gists/5f4973b348a3306cde7917801ad97b39/236d87ed1d4313891dab92d1f815b57cc36b5a65 | python3 -Ic 'import json,sys; f=json.load(sys.stdin)["files"]["bootstrap.sh"]; assert not f["truncated"]; sys.stdout.write(f["content"])' >bootstrap.sh
echo "939e908c8deaa1fc4195726361a96ec80854dc692092e831b7f9959efbf9a929  bootstrap.sh" | sha256sum -c - && bash bootstrap.sh --project <project-id>

It downloads the pinned revision, checks its SHA-256, and only then runs it. In order, each step skipped when already done, it:

  1. installs jq and bws, verified;
  2. stores the access token after two checks: valid on --server, which defaults to the EU cloud, and able to read --project;
  3. installs gh and signs it in with the vault's GITHUB_TOKEN, then sets the git identity;
  4. clones the repository to /srv/projects/claude, or to ~/projects/claude with the sudo line for /srv/projects when that folder is not writable;
  5. runs vault.sh sync and vault.sh timer;
  6. installs pwsh;
  7. runs ./scripts/dev-doctor, whose -Fix installs the remaining tools.

Changing the script. The repository's copy is the source. After every change, run bash scripts/linux/publish-bootstrap.sh (it needs gh with the gist scope) and commit what it writes:

  • scripts/linux/bootstrap.gist, which records the gist, the revision and the SHA-256;
  • the command above.

scripts/ci/check-bootstrap-gist.sh fails the gate while either is behind the script.

A coordinator per repository

Each repository's coordinator runs in that repository's sandbox, the user unit claude-sandbox@<name>. The host's plugins are provisioned into the VM, and no token is inside it. The coordinator keeps running while the owner's workstation sleeps, and other coordinators and the phone reach it over Remote Control. The unit starts the session as the coordinator (below).

Names (#277). Every session is named <user>:<host>/<repo>#<issue>, with the host and the repository by their short names:

  • the home session is claude:<host>;
  • a repository's coordinator is claude:<host>/claude or claude:<host>/feecheck (the sandboxes.conf name);
  • its workers are claude:<host>/claude#276.

: stands for @, which SendMessage refuses in a name. <host> is the short name of the machine: the Linux host's, or the owner's workstation's for its own sessions.

Permissions (#323). claude remote-control spawns its sessions in default mode, whatever the user settings say. So the home unit passes --permission-mode ${PERMISSION_MODE}: auto, unless a drop-in in ~/.config/systemd/user/claude-remote.service.d/ sets another. The tools a coordinator calls unattended—session tags, archiving, starting and messaging sessions, scheduled tasks, pages—are allowed in the checkout's .claude/settings.local.json. Only sessions in that folder read it: workers run in worktrees outside it and keep asking. dev-env:dev-doctor reports missing entries in its Permissions group, and ./scripts/dev-doctor -Fix, run by the owner in a terminal, asks for each repair and adds them; ./scripts/dev-doctor -Fix -Yes adds them to every coordinator checkout without a question. Inside a Claude Code session -Yes applies no permission, baseline or dcg allowlist repair, and the output says to run it from a terminal. The list is plugins/dev-env/permissions-allow.json.

Restarts. systemctl --user restart claude-sandbox@<name> and a reboot stop the sandbox after the stop window, and the coordinator session with it. Nothing it decided is lost: the state file <base_dir>/.coordinator/<repo>.json keeps the tasks and the owner's decisions, and the unit resumes the coordinator's last session at its next start.

The background daemon

Workers (claude --bg) run under the user's background daemon. The first claude --bg starts it on demand, and it stays in that caller's cgroup. claude daemon status shows its pid and origin, and /proc/<pid>/cgroup shows where it lives.

  • In a sandbox, the daemon lives in the VM and ends with the sandbox.
  • On the host, a claude --bg from the home session starts a daemon inside claude-remote.service, and its workers end with that unit's next restart. That is fine for a setup session; development runs in the sandboxes. coordinator start and coordinator resume put a daemon_warning in their plan when the daemon runs, or would start, inside claude-remote.
  • On a host without Docker Sandboxes, the user unit claude-daemon.service runs the daemon (below), so the coordinators and their workers live in its cgroup.

The system unit claude-daemon.service of the old setup (#240) is gone: the cutover removes it. The user unit of the same name (#894) is installed only on a host without Docker Sandboxes.

A host without Docker Sandboxes

A host without /dev/kvm cannot run Docker Sandboxes, for example a virtual server whose provider offers no nested virtualisation. Its coordinators run natively, as systemd user units of claude (#894): the host is set up as one sandbox, the model used before the sandboxes (#319). systemd/coordinators.conf lists them, one line per repository: the name, owner/repo and the checkout, under ~/work (owner decision 2026-11-21: no root step, so no /srv/projects).

Set it up, or bring it up to date, as claude from a clone; it needs no root and runs twice harmlessly:

bash scripts/linux/claude-coordinator.sh setup
claude-coordinator status          # linked into ~/.local/bin by setup

setup installs the script, the config and four units, and:

  • clones a missing checkout with gh and marks each checkout trusted in ~/.claude.json (Claude Code never trusts the home directory, #932);
  • points core.hooksPath of each checkout that has .githooks/pre-push at .githooks, while it is unset: the setting is local and does not come with a clone, and a coordinator without the hook refuses to start workers (#962). Another value is left as it is and reported. The claude-coordinator status command warns about a checkout whose hook is not active;
  • sets the coordinator's base_dir (~/worktrees), max_workers (2) and git_identity while they are unset. The identity is the owner-approved Name <email> of ~/.config/claude-sandbox/git-identity, else GIT_IDENTITY (or SBX_GIT_IDENTITY) of the Bitwarden project, which vault.sh sync writes into the token file; never one from git log;
  • sets crossSessionInbound=accept and remoteControlAtStartup in ~/.claude/settings.json, as sandbox-provision.sh does in a sandbox: messages between a coordinator and its workers are delivered, and every session shows in the app. A remoteControlAtStartup of false is kept;
  • enables and starts:
Unit What it does
claude-daemon.service Claude Code's daemon (claude daemon run), started by claude-coordinator daemon, which stays the unit's main process through an update of Claude Code. Every background session runs under it, with the token file's environment and the stop window. A daemon running outside it (#240) gets no coordinator.
claude-coordinator@<name>.service A oneshot that resumes the coordinator's last session, or starts a new one in the checkout with /workflow:coordinator, named claude:<host>/<name>. One already running is left alone.
claude-coordinator-watch@<name>.timer Every 5 minutes: resumes a coordinator whose session ended. An idle background session stops after about an hour. After 3 resumes within an hour it gives up until systemctl --user restart claude-coordinator@<name>.

What differs from a sandbox. No VM: the coordinators and their workers run as claude on the host, with its files and its token file in reach. They read the GitHub MCP token and the service keys from claude-daemon.service's environment, as the home session does. Claude Code's own sandbox (bubblewrap, which needs bwrap and an AppArmor profile for it on Ubuntu 24.04) is to confine their commands; its settings come in a follow-up of #894, and until then the commands run unconfined. The coordinator's unattended tools need the checkout's .claude/settings.local.json: run coordinator register in each coordinator session once, then ./scripts/dev-doctor -Fix.

A reboot starts claude-daemon.service and each coordinator unit with the user manager (linger is on), and each coordinator resumes its last session.

An update of Claude Code

An update of Claude Code keeps every session of claude-daemon.service running (#1013). The daemon notices that ~/.local/bin/claude changed, starts its successor on the new version, which adopts the sessions, and exits. Had the daemon been the unit's main process, systemd would take that exit for the end of the unit and kill the successor and every session in its cgroup. claude-coordinator daemon is the main process instead: it runs claude daemon run, asks claude daemon status for the successor, and waits on it while it runs in the unit's cgroup. The unit ends only once no daemon runs in it for 10 seconds.

claude-coordinator status names the installed version and the daemon's. They differ only for the moment between an update and the daemon's restart; a difference that stays is a daemon that did not restart, and ~/.claude/daemon.log says why.

The first setup that installs this unit reports that claude-daemon.service runs on older files. The restart that activates it ends the sessions once, so it waits for a moment when no worker is busy: systemctl --user restart claude-daemon, after which the watch resumes the coordinators.

The sandboxes of claude-sandbox@ are not affected: there the daemon runs in the VM, started by claude --bg, and no unit has it as its main process.

The stop window

A stop or restart of a unit ends the Claude sessions in it (#274, owner decision l2). Each unit gives them time to write their transcripts first:

Setting Value Why
KillMode control-group SIGTERM reaches every process of the unit at once, so each claude process writes its own transcript.
KillSignal SIGTERM Claude Code ends on SIGTERM and flushes the transcript on the way.
TimeoutStopSec 120 Two minutes before systemd sends SIGKILL; the default is 90 s.
SendSIGKILL yes A process that hangs is still gone after the window.

Nothing is checkpointed or committed on the way down: coordinator resume continues each task in its worktree (l1).

The user manager's own window. At a shutdown, systemd stops user@<uid>.service, and with it every user unit. Ubuntu's user@.service.d/timeout.conf gives it 5 s, which would SIGKILL every session 5 s into the shutdown (#318, point 9). root-steps.sh prepare adds user@<uid>.service.d/zz-stop-window.conf with TimeoutStopSec=150, enough for the units' 120 s. systemd applies drop-ins in file-name order, whatever their directory. The name sorts after timeout.conf, so its value wins; a stop-window.conf would lose. Check what is active:

systemctl show user@$(id -u claude).service -p TimeoutStopUSec     # 2min 30s
systemctl --user show claude-remote.service sandboxd.service -p Id -p TimeoutStopUSec -p KillMode -p KillSignal

KillSignal=15 is SIGTERM. scripts/tests/systemd-units-test.sh checks the settings in the unit files.

Sandboxes (#306). sbx stop sends no SIGTERM and kills the sandbox at once (measured in issue #260). So the sandbox unit's ExecStop first sends SIGTERM to every claude process inside, waits up to 100 s for them, and runs sbx stop after that; the 120 s window covers both.

Bot sessions in Docker Sandboxes

Each repository's coordinator and its workers run in one Docker Sandbox (sbx), a microVM (#306; owner decisions i1, i2 and l3 on the milestone page, measured in #260).

Layout and contents:

  • One sandbox per repository. A coordinator sees only the sessions in its own VM, so its workers live there too. An idle sandbox takes about 1.2 GB on the host, 2.2 GB with one session; a native session takes about 0.45 GB.
  • Mounts. The checkout (the sandbox's first workspace, where the coordinator starts) and /srv/worktrees, at the same paths. sandboxes.sh refuses anything outside /srv/projects and /srv/worktrees. Everything else on the host, the token file included, is out of reach.
  • Template. sandboxes.sh creates a new sandbox with -t docker/sandbox-templates:claude-code (SANDBOX_TEMPLATE overrides it), the Ubuntu-based image with Node.js, Python, Go and Java. Without -t, sbx 0.51 uses the Debian agent kit docker.io/sbx/claude, which lacks the ICU, xz, node and java that provisioning needs (#665; Docker's base images). An existing sandbox keeps the image it was created from.
  • Tokens never enter the VM. Inside, GH_TOKEN, AIKIDO_API_KEY, CONTEXT7_API_KEY and GEMINI_API_KEY (agy's key, stored as SBX_GEMINI_API_KEY) are placeholders. The sbx proxy puts the real value into requests to the secret's hosts (secrets.md).
  • agy in every sandbox (#632). Provisioning installs the Antigravity CLI from Google's installer, pinned by its sha256 in sandbox-provision.sh. It signs agy in with the Gemini API key (secrets.md), with Gemini 3.8 Flash (High) as its default model (#667; a hard review takes agy --model "Gemini 4 Argon (Medium)"). When Google changes the installer, provisioning reports the mismatch and installs nothing until the script is read and re-pinned.

Lifecycle:

  • systemd owns each sandbox. sandboxd.service runs sbx daemon start in the foreground. The sbx package ships no unit, and without one the daemon lives and dies with the login that started it. claude-sandbox@<name>.service starts the sandbox detached, then the coordinator session inside as claude --bg --remote-control <name>, which shows in claude.ai/code under <name>. A new coordinator runs on Opus at low effort (--model opus --effort low, #789), its workers at high effort. The user manager has no network-online.target, so a start that fails before the network is up is retried (Restart=on-failure).
  • Detached, never attached (#529). An sbx exec starts a stopped sandbox attached, and sbx stops it, with every session inside, once that exec ends. sbx ls shows the unit's sandbox as running (detached) and an attached one as plain running.
    • The unit's start stops an attached sandbox and starts it detached.
    • setup restarts an active unit whose sandbox is stopped or attached after provisioning it.
    • sandboxes.sh (status) reports an attached sandbox as a failure. It also reports an active unit whose coordinator session has no process: the unit is Type=oneshot, so it stays active (exited) when its coordinator is gone.
  • After a start, the sessions of the previous run are gone; their transcripts are not. The unit resumes the coordinator's last session (the session_id in its state file under /srv/worktrees/.coordinator/) when the transcript is in the sandbox. It uses the options the session was started with, and a first prompt to run coordinator status and to schedule its maintenance tick and check-in again (#585). Those options include the model and effort: a coordinator started before #789 keeps its own until /model opus and /effort low. Otherwise it starts a new session. The workers the coordinator then finds as no_live_worker are the coordinator's to resume (#273).
  • A coordinator whose process ends inside the running sandbox comes back by itself (#585). claude-sandbox-watch@<name>.timer runs claude-sandbox watch <name> every 5 minutes while claude-sandbox@<name> is active:
    • When no session in the coordinator's folder is busy or has a pid, the watch resumes that session as the unit's start does, inside the running VM. Neither the sandbox nor the unit is restarted, so the workers keep running. Only a sandbox that stopped under an active unit, which holds no worker, gets a unit restart.
    • It logs to its journal what the VM's background daemon wrote about the session (~/.claude/daemon.log: bg settled <id> (killed) or (done), and the daemon's own restarts): journalctl --user -u claude-sandbox-watch@<name>.
    • After 3 restarts within an hour it gives up. It leaves ~/.local/state/claude-sandbox/<name>.gave-up and fails on every run, which sandboxes.sh reports. Once the cause is found, systemctl --user restart claude-sandbox@<name> starts the coordinator again and clears the marker, so the watch counts from zero.
    • A unit stopped on purpose is left alone.
  • A sandbox whose guest died is listed by sbx ls as running (detached), but every sbx exec answers 409 Conflict: … the sandbox's guest is not running anything — … stop and start the sandbox to boot a fresh guest (#609). Nothing in it runs, coordinator and workers included. The watch restarts the unit for it, as for a stopped sandbox, logs "guest not running", and counts it against the same 3 restarts per hour. A start of the unit stops such a sandbox before it launches the coordinator. sandboxes.sh shows it as a row of its own, and ops-patrol counts its coordinator as not running.
  • Stop gives the sessions their stop window before sbx stop. Never sbx rm: it deletes the VM disk with the plugins, tools, trust and transcripts.

Setting it up

  1. The owner's root step (a), once: sudo bash scripts/linux/root-steps.sh prepare (above).
  2. As claude:

    bash scripts/sandbox/sandboxes.sh setup
    

    One idempotent run; a second run changes nothing. It does, in order:

    • Files and units. The lifecycle script and the token helper go to ~/.local/lib/claude-sandbox/ (0700), the units of systemd/user/ to ~/.config/systemd/user/, then systemctl --user daemon-reload. sandboxd.service is enabled and started. claude-remote.service is installed and left disabled.
    • sbx settings. Remote Control is allowed in sandboxes, and the secrets point at the helper.
    • The network policy: balanced, plus the hosts of scripts/sandbox/network-allow.conf, each for every sandbox or for the one sandbox it names. A host the file drops is removed. An allow rule outside balanced that the file does not name (one added by hand with sbx policy allow) is reported as drift and left alone; setup --prune-network removes it. A new host goes into the file through a pull request, never by hand on the host. The network allowlist page lists every host with its reason.

      sbx policy log shows what was blocked, and dev-doctor's sbx policy log row names the hosts blocked in the last 24 hours. Its network allowlist drift row runs sandboxes.sh network-drift, which compares the live policy with the file.

    • Each sandbox in systemd/sandboxes.conf is created with the memory= and cpus= of its line (default 4g and 4).

    • Root packages. Before provisioning, setup pipes sandbox-root-packages.sh into sbx exec -u root <name>. It installs python3-venv (servers/*/test.sh in the gate needs it) and the libicuNN of the VM's Debian release (pwsh aborts without ICU, #638) when they are missing. That is root inside the throwaway VM, run as claude without sudo, not an escalation on the host (the owner allowed it, #530). On a fresh sandbox, the VM's first-boot apt jobs still hold the apt lock. An apt error that mentions the lock is retried every 5 seconds for up to 300 seconds (VENV_APT_STEP, VENV_APT_WAIT), so one setup after sbx rm is enough (#551). When apt fails, that sandbox is not provisioned. Sandboxes.ps1 setup on Windows runs the same script the same way.
    • Provisioning, from inside the sandbox:
      • pwsh, Pester, PSScriptAnalyzer, pre-commit, semgrep, gitleaks and Vale for the pre-push gate (semgrep, gitleaks and Vale at the pins of the repository's .claude/dev-doctor.json; Vale only where it pins one);
      • dcg with its hook and the owner's git branch -d rule (#514);
      • the <owner> plugins and Aikido's, with every plugin they depend on (superpowers);
      • the commit identity (below);
      • trust for each workspace, since claude --bg refuses an untrusted folder;
      • crossSessionInbound: accept: a message from another session would otherwise wait for review, also in auto mode, the mode the sandbox's sessions start in;
      • the auto-compact window in the VM's ~/.claude/settings.json (below);
      • when the first workspace has a mise.toml: mise (checksum-verified) with the tools it declares, and mise's shims on every session's PATH (#548; a failure there is reported, not fatal);
      • the line's workers= as the coordinator's max_workers;
      • in the VM's ~/.gradle/gradle.properties (#612): org.gradle.daemon.idletimeout=600000, org.gradle.workers.max=2, and org.gradle.jvmargs as the first workspace's own flags plus -Xmx1536m -XX:MaxMetaspaceSize=512m. The heap flags are left out when the workspace sets -Xmx, because the user home's value replaces the project's rather than adding to it. A value set otherwise is reported and kept;
      • every installed <owner> plugin updated (claude plugin update), then, as the last step, the user-level baseline of the installed dev-env plugin with CLAUDE_GITHUB_OWNER of the token file as its owner (claude-baseline.md, #771).
    • Each claude-sandbox@<name> is enabled and started.

    Reviewed copies. setup refuses when an install target lies inside a sandbox workspace. Until #320 makes the host checkout read-only for the sandboxes, the checkout setup copies from is such a workspace. So a file that would change on the host is listed, and copied only with setup --reviewed. Before that, compare it with the installed copy (diff -u) and with the reviewed main on GitHub—never with git in this checkout, whose .git/config a sandbox can write. setup prints the hash of each file it copies. A unit that is active on older files is reported, never restarted, because a restart ends its sessions: systemctl --user restart claude-sandbox@<name> (or sandboxd, which stops every sandbox).

    Sizes. A sandbox runs with the size it was created with. status and setup report one whose size differs from its line, and name sbx rm <name> followed by setup, which recreates it and loses its disk. A VM takes host memory as it touches it and does not give it back, so count each sandbox at its full size against the host's memory.

    Workers. The coordinator checks its memory floor only when it starts a worker, and a Gradle build's memory grows afterwards: in an 8 GB sandbox, three Gradle workers fit at start and were OOM-killed later (#612). A line's workers=<n> caps the workers of that sandbox's coordinator. Provisioning writes it into the coordinator's config on every setup; the config lives in the VM home and is lost by sbx rm. A cap the owner set in the coordinator by hand is kept and reported.

    A sbx daemon a login started is not stopped. setup names sbx daemon stop (which stops every sandbox) and starts no unit beside it. The switch is planned in #318.

    Never call sbx while sandboxd is down (#838): every sbx call starts a daemon of its own, outside sandboxd.service, and it lives on (about 130 MB each). Status lists the pids of sbx daemon start processes outside the unit.

    The alias ~/.sbx/run/d is sbx's short link to its daemon state directory. sbx 0.53 follows it; a link into another state home (a spike that ran sbx with an alternative XDG_STATE_HOME) makes sandboxd fail with untrusted local storage … directory owner … and mode … are not trusted. A spike that runs sbx with another state home removes its alias afterwards. Status and setup name a link that points elsewhere; the fix is to remove the link while sandboxd is stopped (systemctl --user stop sandboxd; rm ~/.sbx/run/d), and sbx recreates it.

  3. Check, as claude:

    bash scripts/sandbox/sandboxes.sh      # every row ✓, then the pending root steps, if any
    ./scripts/dev-doctor -Only Systemd
    
  4. Once the sandboxes run as user units, and no session in the old units must keep running: the owner's root step (b), the cutover (above).

The commit identity

The owner-approved identity of the sandboxes' coordinators and workers is one line Name <email> in ~/.config/claude-sandbox/git-identity on the host (SANDBOX_IDENTITY_FILE), not in the repository. Provisioning:

  • writes it as GIT_AUTHOR_* and GIT_COMMITTER_* into a marked block of the sandbox's /etc/sandbox-persistent.sh, which every shell and session there reads;
  • sets it as git config --global;
  • sets the coordinator's git_identity and base_dir (the line's second workspace) while they are unset, so a recreated sandbox commits without asking the owner.

Without the identity file, setup says so. The coordinator still starts and runs its rounds, but starts no worker until it finds an identity (#937): the setting, this file, or COORDINATOR_GIT_IDENTITY, GIT_IDENTITY or SBX_GIT_IDENTITY in its environment, in that order and read at each command. setup reads the same order, the three keys from the token file.

Session names and Remote Control

Inside the VM the user is agent and the host name is the sandbox's. A coordinator would therefore name its workers agent:<sandbox>/<repo>#<n> and its claims host <sandbox> (#534). To prevent that:

  • setup passes the host's user and host name to provisioning: SESSION_USER and SESSION_HOST when set, else the login and $HOSTNAME (coordinator.py shortens them).
  • Provisioning writes them as SESSION_USER and SESSION_HOST into a second marked block of /etc/sandbox-persistent.sh. coordinator.py takes them before getpass and gethostname. So workers are named claude:<host>/<repo>#<n> and claims name the host, matching the coordinator's own name from claude-sandbox.sh. A claim written under the sandbox's name still counts as this machine's.
  • Provisioning also sets remoteControlAtStartup: true in the VM's ~/.claude/settings.json, so every worker shows in the Desktop app and on claude.ai, also after sbx rm and setup. A false set there by hand is reported and kept.

Nothing else goes into /etc/sandbox-persistent.sh.

The auto-compact window

Every model call re-reads the whole context, so a session's size is what it costs per turn. On a 1M model Claude Code compacts only near 967k tokens; coordinators sat at 250–300k and re-read that on every call (#787: about 250M cache-read tokens against 0.6M output in one morning). So the sessions compact themselves at a set size:

Variable Value Effect
CLAUDE_CODE_AUTO_COMPACT_WINDOW 300000 auto-compaction once the context reaches 300k tokens
CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS 150000 idle compaction (about 54 idle minutes) from 150k instead of 200k
  • Sandboxes: provisioning writes both into the env block of the VM's ~/.claude/settings.json while unset (COMPACT_ENV in sandbox-provision.sh); a value set there by hand is reported and kept. The env block and not /etc/sandbox-persistent.sh: claude-sandbox.sh starts claude --bg through sbx exec without a shell, so the file would reach the Bash tool's shells but not the claude process.
  • Host: claude-remote.service sets both with Environment=; the token file can override them. A changed unit reaches the home session after sandboxes.sh setup and systemctl --user restart claude-remote.
  • Precedence: the variable outranks claude --autocompact, a per-model /autocompact and the autoCompactWindow setting; the window is capped at the model's own. /autocompact in a session shows the window in effect and where it comes from, coordinator config shows it as compaction.window.
  • What a coordinator needs after a compaction is in its state file: plugins/workflow/skills/coordinator/compaction.md. The ops watch's context alarms (400k warning, 600k urgent) sit above the window, so they fire only when compaction did not.

Pushing needs no credential helper

git in a sandbox has no credential helper configured, yet fetch and push to the private repositories work. The sbx proxy puts the github secret into every request to github.com, api.github.com, raw.githubusercontent.com and gist.github.com. dev-doctor recognises a sandbox and reports its "Push credentials" row there as OK. The same goes for the GitHub MCP and Sonatype Guide tokens, which never enter the VM (#545). GitHub packages (npm.pkg.github.com) would need a custom secret.

The github secret uses the token file's GITHUB_PERSONAL_ACCESS_TOKEN, the gh device-flow token with the classic scopes. setup refuses a fine-grained one, on which coordinator status fails. To act as the bot account, rotate it first: bash scripts/linux/rotate.sh rotate github. The helper reads the file on every refresh, so a rotated token reaches the sandboxes without a new setup.

Why provisioning, not a template or a kit

(#530) sbx template save freezes a configured sandbox: a snapshot that cannot be reproduced from the repository. It also leaves out ~/.claude, so plugins would still need provisioning. A kit (a <kit>.yaml and a Dockerfile with install and startup hooks) is the reproducible way and the likely next step. But it cannot be built or tried from inside a sandbox, and it needs a v3 claude workload image in place of the built-in v2 one. Until then, sandbox-provision.sh runs on every setup, idempotent, with checksum-verified downloads, and would become such a kit's hook.

The sandboxes' Anthropic sign-in

The sessions in the sandboxes sign in to Anthropic with sbx's OAuth sign-in, not with a token from the token file: the owner runs /login once inside one sandbox, as the bot account (sbx exec -it <sandbox> claude), and sbx keeps and refreshes the tokens on the host; every sandbox uses that one sign-in. It ends about 28 days after the /login. Past the end, Claude Code empties ~/.claude/.credentials.json in each sandbox and every session there answers Login expired.

  • sandboxes.sh (status) shows a row per running sandbox under "Anthropic sign-in (from inside)" with the end, warns in the last 3 days and fails after the end, on an emptied file or a refused answer.
  • ops-patrol pushes signin:<sandbox>, and each coordinator's maintenance task anthropic-signin warns from inside.

Renew with /login before the end. A sandbox whose file was already emptied needs its own /login as well. The details are in secrets.md.

When sbx loses its Docker sign-in

sbx keeps a Docker sign-in, and its refresh token can be revoked. The daemon then logs token refresh rejected by auth server, deleting credential: refresh token revoked (#589). Why is not known: a sign-in elsewhere, a password or session change on the Docker account, or the token's lifetime. From then on every sbx call fails with error: not signed in to Docker. The VMs and the coordinators in them keep running, but no tool can list, ask or create a sandbox:

  • ops-patrol opens sbx:signed-out ("sbx not signed in on : run sbx login as claude"). While it is open, the coordinator alarms that need sbx to tell a live session from a dead one stay undecided, so it is the one alarm that speaks.
  • claude-sandbox watch logs "sbx is not signed in to Docker" every 5 minutes instead of "next time", and starts nothing.
  • sandboxes.sh (status) shows the sign-in as a row of its own and the sandboxes as unknown; setup stops before its first step that needs sbx.

The way back, as claude, is one command. Either the browser sign-in:

sbx login

or, with no browser at hand, a Docker personal access token with Read scope, the scope Docker's documentation names for a sign-in without a browser. Store the account name and the token once, with hidden input, then sign in from them:

bash scripts/linux/set-token.sh DOCKERHUB_USERNAME
bash scripts/linux/set-token.sh DOCKERHUB_TOKEN
bash scripts/sandbox/sandboxes.sh login

login pipes the token to sbx login --username <name> --password-stdin. The token never reaches a command line, the output or a sandbox: sbx-token, the sandboxes' secret helper, does not serve DOCKERHUB_TOKEN. login does nothing while sbx is signed in, and asks sbx nothing while sandboxd.service is inactive.

Not yet known: whether a PAT sign-in is ever revoked the way the browser sign-in's refresh token was. A PAT has no refresh token, so the reported cause should not apply to it. But sbx does not document how it keeps the sign-in; the patrol alarm says when it happens again.

What a reboot leaves

With linger and the units enabled, the user manager starts at boot, then sandboxd.service, then each claude-sandbox@<name>, which resumes the coordinator. The VM disks survive with the tools, plugins, trust, configuration and transcripts, and so do the secrets and the policy. Without linger, nothing starts until claude logs in.