oficina / equipo Public

Tools cannot read the pasted Claude token through /proc

Astra round 1 (Important): a model's Bash command could read the CLI's
/proc/<pid>/environ, where CLAUDE_CODE_OAUTH_TOKEN is.

Every Bash command already runs in the CLI's own sandbox (enabled,
failIfUnavailable, no unsandboxed commands, no exclusions). Read from
the pinned 2.1.312 binary: that sandbox is a nested bubblewrap with a
new user, PID and mount namespace and a fresh /proc; only
sandbox.enableWeakerNestedSandbox: true binds the inherited /proc, and
there is no automatic fallback. The launcher refuses settings that set
it. The key is not written out, because that would change the certified
implement and review policy hashes.

TestToolCannotReadCLIEnvironment runs a stand-in CLI holding a canary
token in the real namespace and starts a probe the way the CLI starts
a Bash command. Directly, the probe reads the token (the control). In
the sandbox, every environ read fails (the PID, its parent, PID 1, every
visible process and thread, /proc/self/../<pid>, task/<tid>,
<pid>/root/proc/<pid>), and the stand-in is not visible. Mutations
seen to fail it: bind the inherited /proc, drop --unshare-pid, and drop
the namespace helper's PR_SET_DUMPABLE. The launch-policy test fails
if the settings set enableWeakerNestedSandbox, and a policy with it is
refused. The spec paragraph now says what holds and what to check live.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev d3be7d74be91a2df29ce22c1f480c4239ac61657 parent 62aa30c
4 files changed, +196 −13
  • docs/superpowers/specs/2026-11-08-equipo-connections.md +42 −12
  • internal/runner/containment/proc_test.go +136 −0
  • internal/runner/provider/claude/launcher.go +7 −0
  • internal/runner/provider/claude/launcher_test.go +11 −1
diff --git a/docs/superpowers/specs/2026-11-08-equipo-connections.md b/docs/superpowers/specs/2026-11-08-equipo-connections.md
index c2dfda29..fd04de50 100644
--- a/docs/superpowers/specs/2026-11-08-equipo-connections.md
+++ b/docs/superpowers/specs/2026-11-08-equipo-connections.md
@@ -534,18 +534,48 @@ mismatch.
in `.oauth-token` (0600) in the connection's own home, outside every
model-readable path, and reaches each Claude launch as
`CLAUDE_CODE_OAUTH_TOKEN` through bubblewrap's `--args` pipe, never in
-argv; the CLI runs with `CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=1` so the
-model's Bash does not inherit it. Residual risk, accepted and labelled:
-inside the namespace the model's tools run as the same user as the CLI,
-so a tool could read `/proc/<claude pid>/environ`; neither a `hidepid`
-proc mount (same user) nor making the unmodified CLI undumpable closes
-that. The containment's egress reaches only the provider's hosts, so the
-token can go nowhere but where it already works, and a leaked token is
-revoked by running `claude setup-token` again and signing the old
-connection out. To check on the first live paste: `claude auth status
---json` reports `loggedIn: true` with only the variable set; the CLI
-writes no `.credentials.json` into the home; and the variable is absent
-from the model's Bash environment.
+argv, a manifest or a record. Inside the namespace two processes hold
+it in their environment: the namespace helper (PID 1), which makes
+itself non-dumpable before the CLI starts, so the CLI's descendants,
+which have no capabilities, cannot read its `/proc/1/environ`; and the
+unmodified CLI. The model reaches the CLI's process only through tools:
+- Bash: every command runs in the CLI's own sandbox. The policy sets
+ `sandbox.enabled`, `failIfUnavailable`, `allowUnsandboxedCommands:
+ false` and no `excludedCommands`, and the launcher refuses any other
+ settings, so `enableWeakerNestedSandbox` stays at its default, false
+ (it is not written out: that would change the certified policy
+ hashes). In the pinned 2.1.312 (read from the binary's sandbox
+ builder) that sandbox is a nested bubblewrap with a new user, PID and
+ mount namespace and a fresh `/proc` (`--unshare-user --unshare-pid
+ --proc /proc`); only `enableWeakerNestedSandbox: true` makes it bind
+ the inherited `/proc`, and there is no automatic fallback.
+ So a command cannot name the CLI or any ancestor. A second barrier
+ holds on its own: a process in a child user namespace has no ptrace
+ rights over the CLI, so even an inherited `/proc` refuses its
+ `environ`. `CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=1` keeps the variable
+ out of the command's own environment.
+- Read, Glob, Grep: native rules deny `/proc` and `/dev/fd` (and the
+ sandbox denies them too).
+`TestToolCannotReadCLIEnvironment` (containment) runs a stand-in CLI
+holding a canary token inside the real namespace and starts a probe the
+way the CLI starts a Bash command. Run directly, the probe reads the
+token; in the sandbox it reads `/proc/<pid>/environ` for the stand-in's
+PID, its parent, PID 1 and every visible process, each thread's
+`/proc/<pid>/task/<tid>/environ`, `/proc/self/../<pid>/environ` and
+`/proc/<pid>/root/proc/<pid>/environ` (through itself, its parent and
+PID 1), and every read fails and the stand-in is not visible at all.
+Binding the inherited `/proc`, or dropping the PID namespace, makes
+the test fail, and so does a readable `/proc/1/environ` even from a
+direct child. What the test cannot show is the real CLI: on the first
+live paste, check from the model's Bash that `ls /proc` lists only the
+sandbox's own processes and that no `/proc/*/environ` contains
+`CLAUDE_CODE_OAUTH_TOKEN`; and recheck the sandbox builder at every CLI
+version bump. The containment's egress reaches only the provider's
+hosts, and a leaked token is revoked by running `claude setup-token`
+again and signing the old connection out. Also to check on the first
+live paste: `claude auth status --json` reports `loggedIn: true` with
+only the variable set; the CLI writes no `.credentials.json` into the
+home; and the variable is absent from the model's Bash environment.
**Sealing.** The app seals with libsodium `crypto_box_seal` over a
payload `{secret, runner_id, connection_id, provider, endpoint,
diff --git a/internal/runner/containment/proc_test.go b/internal/runner/containment/proc_test.go
new file mode 100644
index 00000000..f63843e3
--- /dev/null
+++ b/internal/runner/containment/proc_test.go
@@ -0,0 +1,136 @@
+//go:build linux
+
+package containment
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "io"
+ "strings"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/runner/provider"
+)
+
+// toolSandbox is the bubblewrap command line the pinned Claude Code 2.1.312
+// builds for every Bash tool command on Linux (its sandbox's R1 builder),
+// with the filesystem and network binds reduced to a read-only root: a
+// new session, a new user, PID and network namespace, and a fresh /proc.
+// The CLI mounts the fresh /proc unless sandbox.enableWeakerNestedSandbox
+// is true, when it binds the inherited one instead; the launcher refuses
+// settings that set it (PolicyInputs in provider/claude).
+var toolSandbox = []string{"/usr/bin/bwrap", "--new-session", "--die-with-parent", "--unshare-net", "--ro-bind", "/", "/", "--dev", "/dev", "--unshare-pid", "--unshare-user", "--proc", "/proc", "--unsetenv", "SRT_ALLOW_NESTED_USERNS", "--"}
+
+// procProbe is what a model's Bash command can try against the process
+// that holds the token (argument 1, its PID in the namespace the CLI runs
+// in; argument 2, its start time, which no PID namespace changes). It
+// reads every environ it can name: the PID itself, its parent, every
+// visible process and thread, and the aliases through /proc/self/..,
+// task/<tid> and another process's root. It prints one "exposed" line
+// per read that shows the token's variable, a "visible" line where it
+// can see the token holder itself, and the number of paths it tried.
+const procProbe = `hp=$1; hstart=$2; tried=0
+try() {
+ tried=$((tried+1))
+ if tr '\0' '\n' <"$1" 2>/dev/null | grep -q '^CLAUDE_CODE_OAUTH_TOKEN='; then echo "exposed $1"; fi
+}
+pids="$hp $PPID 1 2 $(ls /proc | grep -E '^[0-9]+$')"
+for p in $pids; do
+ try "/proc/$p/environ"
+ try "/proc/self/../$p/environ"
+ try "/proc/$p/root/proc/$hp/environ"
+ for task in /proc/$p/task/*; do try "$task/environ"; done
+ stat=$(cat /proc/$p/stat 2>/dev/null) || continue
+ fields=(${stat##*) })
+ if [ "${fields[19]}" = "$hstart" ]; then echo "visible $p"; fi
+done
+try "/proc/$hp/task/$hp/environ"
+try "/proc/self/root/proc/$hp/environ"
+try "/proc/1/root/proc/$hp/environ"
+try "/proc/$PPID/root/proc/$hp/environ"
+echo "tried $tried"
+`
+
+// The harness stands in for the claude CLI: it holds the token in its
+// environment, as LaunchSecretEnv delivers it, and starts the probe as
+// the CLI starts a Bash tool command: without the token in the child's
+// environment (CLAUDE_CODE_SUBPROCESS_ENV_SCRUB), once directly and once
+// in the CLI's tool sandbox.
+const procHarness = `import json,os,subprocess,sys
+assert os.environ.get("CLAUDE_CODE_OAUTH_TOKEN")
+env={k:v for k,v in os.environ.items() if k!="CLAUDE_CODE_OAUTH_TOKEN"}
+sandbox=json.loads(%q); probe=json.loads(%q)
+me=str(os.getpid()); start=open("/proc/self/stat").read().rsplit(")",1)[1].split()[19]
+out={"pid":me}
+for name,prefix in [("direct",[]),("sandboxed",sandbox)]:
+ r=subprocess.run(prefix+["/usr/bin/bash","-c",probe,"probe",me,start],env=env,stdin=subprocess.DEVNULL,capture_output=True,text=True,timeout=20)
+ out[name]={"code":r.returncode,"out":r.stdout,"err":r.stderr[-400:]}
+print(json.dumps(out),flush=True)
+`
+
+type probeRun struct {
+ Code int
+ Out, Err string
+}
+
+// The pasted token is in the CLI's environment. A command the model runs
+// through the Bash tool must not read it from /proc: the tool sandbox's
+// fresh PID namespace and /proc hide the CLI and every ancestor, under
+// every alias. The direct run is the control: without the namespace the
+// same probe reads the token, so the probe is not vacuous.
+func TestToolCannotReadCLIEnvironment(t *testing.T) {
+ m, l := fixture(t)
+ m.secretEnv = func(provider.Launch) (map[string]string, error) {
+ return map[string]string{provider.OAuthTokenEnv: canary, provider.ScrubEnv: "1"}, nil
+ }
+ sandbox, _ := json.Marshal(toolSandbox)
+ probe, _ := json.Marshal(procProbe)
+ p := launch(t, m, l, fmt.Sprintf(procHarness, sandbox, probe))
+ raw, err := io.ReadAll(p.Stdout())
+ if err != nil {
+ t.Fatal(err)
+ }
+ if exit, err := p.Wait(context.Background()); err != nil || exit.Code != 0 {
+ errout, _ := io.ReadAll(p.Stderr())
+ t.Fatalf("harness: %+v %v %s", exit, err, errout)
+ }
+ if strings.Contains(string(raw), canary) {
+ t.Fatal("the token's value reached the probe's output")
+ }
+ var out struct {
+ PID string
+ Direct, Sandboxed probeRun
+ }
+ if err = json.Unmarshal(raw, &out); err != nil {
+ t.Fatalf("harness output %q: %v", raw, err)
+ }
+ // Control: run directly, the probe reads the CLI's environment.
+ if out.Direct.Code != 0 || !strings.Contains(out.Direct.Out, "exposed /proc/"+out.PID+"/environ\n") || !strings.Contains(out.Direct.Out, "visible "+out.PID+"\n") {
+ t.Fatalf("control probe found nothing, so it proves nothing: %+v", out.Direct)
+ }
+ // The namespace helper (PID 1) holds the token too, but is not
+ // dumpable: not even a direct child of the CLI reads its environment.
+ if strings.Contains(out.Direct.Out, "exposed /proc/1/") {
+ t.Fatalf("the namespace helper's environment is readable: %s", out.Direct.Out)
+ }
+ run := out.Sandboxed
+ if run.Code != 0 || !strings.HasPrefix(lastLine(run.Out), "tried ") {
+ t.Fatalf("tool sandbox did not start inside the namespace: %+v", run)
+ }
+ var tried int
+ if _, err = fmt.Sscanf(lastLine(run.Out), "tried %d", &tried); err != nil || tried < 12 {
+ t.Fatalf("probe tried %d paths", tried)
+ }
+ t.Logf("control: %d reads exposed the token; sandboxed: %d paths tried", strings.Count(out.Direct.Out, "exposed "), tried)
+ for _, line := range strings.Split(strings.TrimSpace(run.Out), "\n") {
+ if strings.HasPrefix(line, "exposed ") || strings.HasPrefix(line, "visible ") {
+ t.Errorf("from the tool sandbox: %s", line)
+ }
+ }
+}
+
+func lastLine(s string) string {
+ lines := strings.Split(strings.TrimSpace(s), "\n")
+ return lines[len(lines)-1]
+}
diff --git a/internal/runner/provider/claude/launcher.go b/internal/runner/provider/claude/launcher.go
index 85170c6b..27216a74 100644
--- a/internal/runner/provider/claude/launcher.go
+++ b/internal/runner/provider/claude/launcher.go
@@ -163,6 +163,13 @@ func PolicyInputs(b provider.Binding, in provider.PolicyInputs, specialist, mode
ask = append(ask, tool+"(//workspace/**)")
}
}
+ // Every Bash command runs in the CLI's sandbox: in the pinned CLI a
+ // new user and PID namespace with a fresh /proc, so it cannot name the
+ // CLI or read its environment, where a token connection's token is.
+ // The CLI binds the inherited /proc only when
+ // sandbox.enableWeakerNestedSandbox is true; it is left at its false
+ // default (adding the key would change the certified policy hashes),
+ // and validatePolicy refuses settings that differ from these.
settings := map[string]any{
"env": map[string]string{"MCP_TOOL_TIMEOUT": "600000"},
"disableAllHooks": true, "enabledPlugins": map[string]any{"agents-md@builtin": false, "plugin-authoring@builtin": false}, "autoMemoryEnabled": false, "autoDreamEnabled": false,
diff --git a/internal/runner/provider/claude/launcher_test.go b/internal/runner/provider/claude/launcher_test.go
index d3ccafad..1a73ea6e 100644
--- a/internal/runner/provider/claude/launcher_test.go
+++ b/internal/runner/provider/claude/launcher_test.go
@@ -341,6 +341,11 @@ func TestClaudeLaunchPolicy(t *testing.T) {
if sandbox["autoAllowBashIfSandboxed"] != true {
t.Fatal("automatic shell approval enabled")
}
+ // A Bash command gets its own PID namespace and a fresh /proc,
+ // so it cannot read the CLI's environment (the pasted token).
+ if v, set := sandbox["enableWeakerNestedSandbox"]; set && v != false {
+ t.Fatal("tool sandbox may inherit /proc")
+ }
if len(sandbox["excludedCommands"].([]any)) != 0 {
t.Fatal("excluded commands")
}
@@ -580,7 +585,7 @@ func TestClaudeObservedIdentity(t *testing.T) {
}
}
func TestClaudePolicyRefusals(t *testing.T) {
- for _, field := range []string{"settings", "autoMemoryEnabled", "autoDreamEnabled", "plugin-authoring@builtin", "mcp", "tools", "argv", "env", "version", "helper", "managed", "managed_instruction", "hash"} {
+ for _, field := range []string{"settings", "weaker-proc", "autoMemoryEnabled", "autoDreamEnabled", "plugin-authoring@builtin", "mcp", "tools", "argv", "env", "version", "helper", "managed", "managed_instruction", "hash"} {
t.Run(field, func(t *testing.T) {
f := fixtureFor(t, "Engineering")
in := f.inputs
@@ -599,6 +604,11 @@ func TestClaudePolicyRefusals(t *testing.T) {
json.Unmarshal(in.Settings, &v)
v["sandbox"].(map[string]any)["enabled"] = false
in.Settings, _ = json.Marshal(v)
+ case "weaker-proc":
+ var v map[string]any
+ json.Unmarshal(in.Settings, &v)
+ v["sandbox"].(map[string]any)["enableWeakerNestedSandbox"] = true
+ in.Settings, _ = json.Marshal(v)
case "mcp":
in.MCP = json.RawMessage(`{"mcpServers":{"other":{"command":"/opt/evil"}}}`)
case "tools":