oficina / equipo Public

Never run Pi file tools beside a shell command

Pi gates every call in a message before running them together, so a
shell command could swap a checked path for a link before a file tool
opens it. The extension refuses whichever of the two is gated while
the other runs. Adds a batch test with a positive control and a
stdio-only descriptor probe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude pushed by paul@keymail.dev c0e79c70a42cb955472b4a3a290fed47da241d7e parent f181df5
4 files changed, +139 −7
  • docs/superpowers/specs/2026-11-13-pi-isolated-shell.md +12 −2
  • internal/fakepi/tensorx.go +19 −3
  • internal/runner/provider/pi/batch_linux_test.go +84 −0
  • internal/runner/provider/pi_extension.ts +24 −2

CI passed — run details

diff --git a/docs/superpowers/specs/2026-11-13-pi-isolated-shell.md b/docs/superpowers/specs/2026-11-13-pi-isolated-shell.md
index b93fc2d2..e5748d08 100644
--- a/docs/superpowers/specs/2026-11-13-pi-isolated-shell.md
+++ b/docs/superpowers/specs/2026-11-13-pi-isolated-shell.md
@@ -32,8 +32,18 @@ The filesystem contains read-only `/usr` and `/etc`, a writable workspace and
shell-only temporary directory, and an empty home. The CLI's home, config,
package tree, key file, tool socket and relay socket are absent. Shell exit
also ends its background processes. Pi's native file tools are confined to the
-workspace; its settings, model and MCP files are individually mounted read-only.
-The containing directory stays writable for Pi's settings lock.
+workspace by a path check when each call is gated; its settings, model and MCP
+files are individually mounted read-only. The containing directory stays
+writable for Pi's settings lock.
+
+Pi gates every call in one assistant message before running them together, so
+the gate-time path check alone could race a shell command that swaps a checked
+path for a link. Equipo's extension therefore never lets a file tool and a
+shell command run at the same time: whichever is gated second while the other
+is still running is refused ("Run file tools and shell commands in separate
+messages"). Calls of one kind still run in parallel, and separate messages run
+in turn. TestPiBatchSeparatesShellAndFileTools covers both orders with a
+positive control. The shell inherits only stdio (TestPiShellInheritedDescriptors).
Engineering gets the same configured Go root and optional module cache as
Claude and Codex. A Pi attempt retains directory descriptors using the shared
diff --git a/internal/fakepi/tensorx.go b/internal/fakepi/tensorx.go
index 9d5aa9e5..5dc5b490 100644
--- a/internal/fakepi/tensorx.go
+++ b/internal/fakepi/tensorx.go
@@ -174,9 +174,25 @@ func (f *TensorX) serve(w http.ResponseWriter, r *http.Request) {
if role == "user" {
text = steps(text)
}
- if role == "user" && strings.HasPrefix(text, "CALL ") {
- parts := strings.SplitN(text, " ", 3)
- chunk(with("choices", []any{map[string]any{"index": 0, "delta": map[string]any{"role": "assistant", "tool_calls": []any{map[string]any{"index": 0, "id": "call_1", "type": "function", "function": map[string]any{"name": parts[1], "arguments": parts[2]}}}}}}))
+ if role == "user" && (strings.HasPrefix(text, "CALL ") || strings.HasPrefix(text, "BATCH ")) {
+ var calls []struct {
+ Name string `json:"name"`
+ Arguments json.RawMessage `json:"arguments"`
+ }
+ if strings.HasPrefix(text, "BATCH ") {
+ _ = json.Unmarshal([]byte(strings.TrimPrefix(text, "BATCH ")), &calls)
+ } else {
+ parts := strings.SplitN(text, " ", 3)
+ calls = append(calls, struct {
+ Name string `json:"name"`
+ Arguments json.RawMessage `json:"arguments"`
+ }{parts[1], json.RawMessage(parts[2])})
+ }
+ var batch []any
+ for i, c := range calls {
+ batch = append(batch, map[string]any{"index": i, "id": fmt.Sprintf("call_%d", i+1), "type": "function", "function": map[string]any{"name": c.Name, "arguments": string(c.Arguments)}})
+ }
+ chunk(with("choices", []any{map[string]any{"index": 0, "delta": map[string]any{"role": "assistant", "tool_calls": batch}}}))
chunk(with("choices", []any{map[string]any{"index": 0, "delta": map[string]any{}, "finish_reason": "tool_calls"}}))
} else {
reply := "ok done"
diff --git a/internal/runner/provider/pi/batch_linux_test.go b/internal/runner/provider/pi/batch_linux_test.go
new file mode 100644
index 00000000..07e2399e
--- /dev/null
+++ b/internal/runner/provider/pi/batch_linux_test.go
@@ -0,0 +1,84 @@
+package pi
+
+import (
+ "encoding/json"
+ "os"
+ "path/filepath"
+ "testing"
+)
+
+// Pi gates every call in a message before running them together. A file
+// tool and a shell command in one message must never both run: the shell
+// could swap a checked path for a link before the file tool opens it.
+func TestPiBatchSeparatesShellAndFileTools(t *testing.T) {
+ h := newHarness(t, realInstall(t))
+ work := t.TempDir()
+ for _, name := range []string{"a.txt", "b.txt"} {
+ if err := os.WriteFile(filepath.Join(work, name), []byte("plain\n"), 0600); err != nil {
+ t.Fatal(err)
+ }
+ }
+ r := h.open(work, "implement", []string{"submit_candidate"}, "")
+ batch := func(calls ...map[string]any) []ToolResult {
+ t.Helper()
+ raw, _ := json.Marshal(calls)
+ got := results(r.prompt(t, "BATCH "+string(raw), "allow"))
+ if len(got) != len(calls) {
+ t.Fatalf("batch returned %d results, want %d", len(got), len(calls))
+ }
+ return got
+ }
+ bash := map[string]any{"name": "bash", "arguments": map[string]string{"command": "echo shell-ran"}}
+ read := func(name string) map[string]any {
+ return map[string]any{"name": "read", "arguments": map[string]string{"path": "/workspace/" + name}}
+ }
+ // Results arrive in completion order; a refused call is an error result
+ // (the files exist, so a read that runs does not error).
+ refused := func(res ToolResult) bool { return res.IsError }
+ byTool := func(rs []ToolResult, tool string) ToolResult {
+ t.Helper()
+ for _, r := range rs {
+ if r.Tool == tool {
+ return r
+ }
+ }
+ t.Fatalf("no %s result in %+v", tool, rs)
+ return ToolResult{}
+ }
+ // Positive control: file tools alone, and a shell command alone, run.
+ for _, res := range batch(read("a.txt"), read("b.txt")) {
+ if refused(res) {
+ t.Fatal("two file reads in one message were refused")
+ }
+ }
+ if res := batch(bash); refused(res[0]) {
+ t.Fatal("a lone shell command was refused")
+ }
+ // Shell first: the read must not run beside it.
+ if res := batch(bash, read("a.txt")); refused(byTool(res, "bash")) || !refused(byTool(res, "read")) {
+ t.Fatalf("shell then read: %+v", res)
+ }
+ // File tool first: the shell command must not run beside it.
+ if res := batch(read("a.txt"), bash); refused(byTool(res, "read")) || !refused(byTool(res, "bash")) {
+ t.Fatalf("read then shell: %+v", res)
+ }
+ // Separate messages still work in turn.
+ if res := batch(read("a.txt")); refused(res[0]) {
+ t.Fatal("a read after a mixed batch was refused")
+ }
+}
+
+func TestPiShellInheritedDescriptors(t *testing.T) {
+ h := newHarness(t, realInstall(t))
+ r := h.open(t.TempDir(), "implement", []string{"submit_candidate"}, "")
+ shellOK(t, h, r, `python3 - <<'PY'
+import os
+fds=[]
+for name in os.listdir('/proc/self/fd'):
+ try: os.fstat(int(name))
+ except OSError: continue
+ fds.append(int(name))
+assert sorted(fds)==[0,1,2],sorted(fds)
+print('stdio-only')
+PY`, "stdio-only")
+}
diff --git a/internal/runner/provider/pi_extension.ts b/internal/runner/provider/pi_extension.ts
index a31c0e09..85ee8c07 100644
--- a/internal/runner/provider/pi_extension.ts
+++ b/internal/runner/provider/pi_extension.ts
@@ -28,17 +28,39 @@ export default function (pi: any) {
}
return path === confine || path.startsWith(confine + "/");
};
+ // Pi gates every call in a message before running them together, so a
+ // shell command could swap a checked path for a link before a file tool
+ // opens it. A file tool and a shell command never run at the same time.
+ const running = new Map<string, string>();
+ const kindOf = (name: string): string => (name === "bash" ? "shell" : fileTools.has(name) ? "file" : "");
+ const clash = (kind: string): boolean =>
+ kind !== "" && [...running.values()].some((k) => k !== kind);
+ pi.on("tool_result", async (event: any) => {
+ running.delete(event.toolCallId);
+ return undefined;
+ });
+ pi.on("agent_end", async () => {
+ running.clear();
+ });
pi.on("tool_call", async (event: any, ctx: any) => {
+ const kind = kindOf(event.toolName);
+ if (clash(kind)) {
+ return { block: true, reason: "Run file tools and shell commands in separate messages." };
+ }
+ const allow = () => {
+ if (kind !== "") running.set(event.toolCallId, kind);
+ return undefined;
+ };
let ok = allowed.has(event.toolName);
if (ok && confine !== "" && fileTools.has(event.toolName)) {
ok = inside(event.input?.path);
}
if (ok) {
- return undefined;
+ return allow();
}
const yes = await ctx.ui.confirm("equipo:tool_call", JSON.stringify({ id: event.toolCallId, tool: event.toolName, args: event.input }));
if (yes === true) {
- return undefined;
+ return clash(kind) ? { block: true, reason: "Run file tools and shell commands in separate messages." } : allow();
}
return { block: true, reason: "Equipo did not allow this call." };
});