Plan: a kernel floor under bash - the landstrip binary runs every shell command with a policy per mode
Closes: #18 (phase one; Windows is filed as a follow-up). Branch: feat/kernel-sandbox. Status: Done (2026-10-04) — shipped in 0.92.0, reverted in 0.92.1 (#327); lessons on #18
TL;DR
Every control in this package is policy, and each assumes the command was
classified right; classification is undecidable, since any program can
write. #18’s spike proved the fix is capability removal, and that the
landstrip engine does it. Adopting the pi-landstrip extension is blocked
three ways (#18, 2026-10-04): it replaces the bash tool pi-workflow owns,
so pi refuses to start; it parses our seeded agent files with its own
schema and denies every tool when they fail; its policy merge only widens.
This plan uses the engine without the extension. pi’s bash tool takes a
spawnHook that rewrites the command before the shell is spawned (the
Evidence section quotes it), and pi-workflow’s sequentialBash
(batch-order.ts:144-154) builds that tool per call. pi-modes decides
the policy and publishes a hook through the runtime bridge, which already
carries optional members (runtime-bridge.ts:24-68); pi-workflow applies
it and decides nothing. The hook turns <command> into
printf '%s' "$GADHS_SANDBOX_POLICY" | "$GADHS_SANDBOX_BIN" run -p - --policy-format json — bash -c "$GADHS_SANDBOX_CMD",
the three values carried in env: no quoting of the command, no temp files,
and pi keeps streaming, timeouts, abort and truncation as today.
Measured on this box (landstrip 0.19.6, Landlock ABI 9 + seccomp; #18,
2026-10-04): the plan policy refused a Python write, a shell redirect and
an out-of-tree write while cat, git status/log/diff and exec worked;
the auto policy allowed workspace writes and a commit and refused
out-of-tree writes; a denyRead on a credentials directory held; the same
write without landstrip succeeded. Phase one changes no rubric: on
unsandboxed hosts the judge is still the only line. What stays, by name,
is listed under Design.
Design
The engine, and why this one
Three candidates were compared (#18, notes 2026-09-30 and 2026-10-04):
landstrip (@landstrip/landstrip-api) |
Anthropic sandbox-runtime (srt) |
Codex linux-sandbox |
|
|---|---|---|---|
Linux mechanism |
Landlock + seccomp: unprivileged, no namespaces |
bubblewrap with a network namespace: needs unprivileged user namespaces, which hardened distros disable |
bubblewrap + seccomp |
macOS |
Seatbelt |
Seatbelt ( |
none |
Windows |
AppContainer (needs explicit read grants per program) |
a dedicated local user + WFP egress fence |
none |
Distribution |
npm, native binary per platform, no system package |
npm; Linux needs |
part of the Codex tree, not a standalone artifact |
Network |
all-or-nothing, or an HTTPS proxy by domain |
proxies only (HTTP and SOCKS); SSH would need a SOCKS-aware client |
namespace off |
Policy shape |
|
the same four lists; |
CLI flags |
Licence |
API Apache-2.0; binary LGPL-3.0, run as a separate process |
check before adoption |
Apache-2.0 |
landstrip is chosen for phase one: no system dependency, no user namespaces, SSH keeps working with the network on, and it is the engine already measured. The filesystem policy shape is the same as `srt’s, so the policy builder is engine-neutral; only the adapter that turns a policy into an argv knows landstrip. That makes the choice reversible, so no ADR. The version is pinned exactly: 162 releases in four months, one maintainer, pre-1.0.
Where each piece lives
|
|
|
The adapter: find the binary ( |
|
|
|
|
|
The optional member’s type. NOOP returns undefined. |
|
|
The policies
Paths are resolved with realpath before they enter a policy (a symlinked
workspace is granted by its real path, which is what the kernel sees).
| plan | auto, manual | |
|---|---|---|
|
|
the workspace; |
|
|
the same |
|
true (see Decision 1) |
true |
Two rules the builder enforces, both measured (#18, 2026-10-04):
-
A deny never sits inside an allow root. A
denyReadinside the workspace madegit statusunable to list.and new files unreadable. Any deny whose path is inside an allow root is dropped from the policy, and the drop is reported once per session (the notice names the path). The workspace being$HOMEitself is the case this hits. -
The allow list holds only paths that exist, so a cache directory a box lacks is not created by the grant.
yolo gets no hook (every ask is allowed by design; the sandbox would be
the one control left, and yolo promises none).
Plan mode’s one writable file, the plan draft under ~/.pi/agent/plans/,
is written by pi’s write tool, in-process; bash never needs it.
Erratum (2026-10-04): the approved draft listed all of ~/.pi/agent in
denyRead, claiming cat ~/.pi/agent/settings.json was already a deny
rule. It is a shipped allow (modes.json, pinned in
test/rule-precedence.test.ts). The floor denies ~/.pi/agent/auth.json,
the credential the file-tool rules deny, and leaves the rest readable.
Failure modes, each named fail-open or fail-closed
|
Binary present and |
|
When the sandbox is unusable, every bash ask is refused with that reason. For boxes where the floor is the point. |
|
No hook, no notice. |
A deny nested inside an allow root (the workspace is |
The nested deny is dropped (keeping it breaks the workspace, see the rule above), the notice names the path, and the facts header lists it ( |
The policy fails to validate at the binary ( |
Treated as |
A command the kernel refuses is not a failure mode of the floor: it is the floor working, and the agent sees why (below).
doctor runs once, lazily, on the first bash call (not at load: a
sub-second spawn, but startup should not pay it). Its result is cached
for the session.
What the agent sees on a refusal
landstrip prints one JSON line per denial to stderr
({"kind":"filesystem","code":"FILESYSTEM_DENIED",…,"suggested_grant":{…}})
beside the program’s own Permission denied. Phase one keeps that: it is
accurate and names the path. The mode prompts gain one sentence: "In plan
mode the kernel refuses writes; a FILESYSTEM_DENIED line is the sandbox,
not a bug to work around. If a task in auto needs a path the sandbox
refuses, say so; the human can add it to sandbox.extraWrite." A tidier
rendering (--trap <fd>) is a follow-up.
What is unchanged, by name
-
prompts/plan-judge.md,JUDGE_SYSTEM_PROMPT, the valve, every rule inmodes.json(the credential deny rules for bash become redundant on sandboxed hosts; they stay for file tools and unsandboxed hosts). -
pi-bash, the commit guard, batch order. -
user_bash(!cmdtyped by the human) is pi’s own tool, not wrapped. -
Subagents: pi-subagents builds each one with a
DefaultResourceLoaderover the same settings (itssrc/index.ts,createResourceLoader), so a subagent loads pi-workflow and pi-modes too, gets the same registeredbash, and its pi-modes publishes the bridge on the sharedglobalThis. The floor covers them; a test pins it (a Verify-shaped subagent in plan mode cannot write).
Decisions for the operator
-
Plan mode’s network stays on (operator, 2026-10-04: research needs it). The plan judge allows network reads (
glab issue view,git fetch,curlGET) and denies remote mutations; that stays its job. Plan mode’s kernel floor is "no local writes". -
Auto’s write scope: workspace + scratch + known caches, not
$HOME.$HOMEwith denies inside it is the nested-deny configuration the measurement showed broken. The cache list will be incomplete for some tool; the cost is one visible refusal naming the path and a one-line config fix. Field round six measures how often. -
Default
onwith a visible fallback, notrequired. A developer on an old kernel or WSL1 keeps a working shell and sees why the floor is off.requiredexists for boxes where the floor is the point.
Scope
Units
-
Policy builder (
sandbox-policy.ts+ test): the table above, the two rules, realpath, existence filter,extraWrite/extraDenyRead. Property test: for arbitrary workspace/home/deny lists, no deny in the output lies inside an allow root. -
Config (
config.ts+ test): thesandboxblock, validated; bad values refuse to start, as other config does. -
Adapter (
sandbox.ts+ test): binary lookup, lazydoctor, the hook (env + rewritten command), the degraded decision persandbox.mode, the facts line. Unit tests with a fake binary path and a fakedoctor. Real-binary tests,describe.skipIf(!linux \|\| doctor not ok): plan policy refusespython3 -c 'open(…,"w")'andecho x > f, allowscatandgit status; auto allows a workspace write and refuses one outside;denyReadholds;-p -reads the policy from stdin; a sandboxedsleep 60is dead after pi’s abort (pi kills the process group,utils/shell.js:157-186; the test proves landstrip’s child is in it, else the adapter mustsetsid-proof it). -
Bridge and wiring (
session-wiring.ts,runtime-bridge.ts,batch-order.ts+ tests): the optional member;sequentialBashapplies it; a test with a fake hook that sets an env marker and runsenvthrough the real tool shows the marker; NOOP bridge → no hook. -
Prompts and facts: the sentence in auto’s and plan’s system prompts;
sandbox:infactsHeader(judge.ts), pinned by the header contract test. No rubric change;eval --repeat 3must stay 0 unsafe (the header changes, so the gate runs). -
Docs and release notes:
modes.adocgets a "Kernel sandbox" section (what it confines, what it does not, the config, the notice, the refusal line);architecture.adocnames the dependency; CHANGELOGUnreleased. The plan page underdocs/modules/ROOT/pages/plans/with a nav entry. -
Dependency:
@landstrip/landstrip-apipinned exactly in pi-modes; consumer-sim must still install clean (its optional per-platform packages resolve under npm). -
Close: the MR carries
Closes #18. On merge, #18 gets one line: the merge SHA, and the numbers of the follow-up issues below, which are filed at implementation start (plan mode cannot file them): Windows (AppContainer read grants), the plan rubric reduced to remote effects on sandboxed hosts,--trap <fd>rendering, mid-run "grant this path" approval, andsrtbehind the same adapter. The plan page’s status goes to Done with the date. -
Field: after release, round six of the field study on the release (operator’s call, as always) measures plan-mode and auto-mode friction from the floor; its report goes on #18 and #291.
Out of scope, to be filed at implementation start (see the Close unit)
Erratum (2026-10-04, after release): reverted in 0.92.1 (#327). In a live session the floor broke GPG commit signing, git over SSH, docker’s auth and Vertex calls from child processes: the kernel cannot tell the agent reading a credential from a tool using it on the developer’s behalf. Narrowed to a plan-only read-only floor, it duplicated plan mode’s policy-level rule and still needed carve-outs for research tools (glab rewrites its config, npm writes its cache). Operator decision: revert; lessons on #18.
Erratum (2026-10-04): filed as #321 (Windows), #322 (the plan rubric), #323 (--trap), #324 (mid-run grants), #325 (srt).
Erratum (2026-10-04, cold review): the floor counts as on only when the
binary works AND something applies the hook to bash. pi-workflow says so
through the bridge (bashHookApplied) when it registers its bash. pi-modes
alone enforces nothing, so it reports the floor off and required
refuses. The judge’s facts line computes the policy for the ask’s directory
first, so a nested deny is named before the first command runs. The
sandbox is claimed first-come on a process slot, like the bridge, so a
subagent’s pi-modes reads its parent’s sandbox: the one whose hook its
bash applies. A mode with no floor is told so in the facts.
Erratum (2026-10-04): pinned @landstrip/landstrip-api 0.19.4, not the
measured 0.19.6. 0.19.6 was hours old, inside pnpm’s minimumReleaseAge
hold, and pnpm 11 silently wrote minimumReleaseAgeExclude entries for it
into pnpm-workspace.yaml. An exemption from that control is not this
plan’s to make. 0.19.4 has cleared the hold, and the real-binary tests
pass on it.
-
Windows (AppContainer read grants per program;
requiredon Windows refuses bash until then). -
The plan rubric reduced to remote effects on sandboxed hosts (after a field round shows the floor holding).
-
--trap <fd>rendering of denials. -
Interactive "grant this path" approval mid-run (pi-landstrip has it; our ask broker could carry it).
-
srtas an alternative engine behind the same adapter, if landstrip stalls.
Versions
pi-modes minor, pi-workflow minor (a bridge member and a hook), meta minor. What is refused changes (plan-mode writes now fail at the kernel, auto-mode out-of-tree writes too), so minor, not patch.
Acceptance
-
With the sandbox on, in plan mode,
python3 -c 'open("x","w")'fails with EACCES and no file exists; the judge was not what refused it (the audit log shows the judge’s allow or the rule’s allow, and the kernel’s denial in the tool result). -
In auto mode a write to
~/.ssh/xor/etc/xfails; a write in the workspace,/tmpand~/.npmsucceeds;pnpm installandpip install --user-free flows in the field harness’s scenarios run. -
A timed-out sandboxed command leaves no process behind.
-
On a box without the binary, bash works and one notice says why.
-
node tools/task.mjs validategreen;eval --repeat 30 unsafe.
Evidence outside the repository
The seams this plan rests on are not in the tree, so the cold reviewer cannot open them. Quoted here, as read on 2026-10-04; implementation re-reads each before relying on it.
pi-coding-agent 1.0.2, dist/core/tools/bash.js (the prefix is prepended,
then the hook runs on {command, cwd, env}, and its result is what pi
spawns):
135 function resolveSpawnContext(command, cwd, spawnHook, exposeSessionEnvironment, ctx) {
136 const env = { ...getShellEnv() };
155 const baseContext = { command, cwd, env };
156 return spawnHook ? spawnHook(baseContext) : baseContext;
173 const resolvedCommand = commandPrefix ? `${commandPrefix}\n${command}` : command;
174 const spawnContext = resolveSpawnContext(resolvedCommand, ctx?.cwd || cwd, spawnHook, exposeSessionEnvironment, ctx);
dist/core/tools/bash.d.ts:64-80: BashSpawnContext {command, cwd, env},
BashSpawnHook = (context) ⇒ BashSpawnContext, BashToolOptions.spawnHook.
createLocalShellOperations (bash.js:48-66) spawns
shellConfig.shell […args, command] with detached: true and the
hook’s env.
dist/utils/shell.js:157-186 killProcessTree(pid): on Unix
process.kill(-pid, "SIGKILL"), falling back to process.kill(pid). Hence
the test that a sandboxed sleep dies on abort.
@landstrip/landstrip-api 0.19.6 (npm pack, 2026-10-04): bin/landstrip.js,
lib/index.js exporting binaryPath(), optional per-platform packages
@landstrip/landstrip-{linux,darwin,win32}-{x64,arm64}; landstrip run --help
lists --policy-format <FORMAT> ("Required when a policy is read from
standard input") and --trap <FD>. landstrip doctor here:
{"ok":true,"platform":"linux","implementation":"landlock+seccomp"}.
@gotgenes/pi-subagents (installed), src/index.ts:100-125:
createResourceLoader: (opts) ⇒ new DefaultResourceLoader(opts) and
createSession: … createAgentSession({… resourceLoader …}), with
excludedExtensionPackages the only subtraction. So a subagent loads the
same extensions as its parent.