Skip to content

Commit ba50963

Browse files
smashruclaude
andcommitted
fix(runner): keep parent secrets out of a Grok writer's shell
A Grok writer's shell is pre-approved, and Grok's workspace sandbox reads the whole host and, on macOS, never blocks child-process network. The runner passed it the parent's full environment, so a prompt-injected writer could send any token there to the network. Grok writers now get an allowlisted environment: paths, user, shell, locale, terminal, proxy and CA settings, and GROK_* and XAI_*. Other lanes keep the existing identity-only scrub. The dispatch reference now states the real trust boundary instead of claiming commands outside the workspace are cancelled. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 2431509 commit ba50963

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

‎plugins/pstack/skills/poteto-mode/references/provider-dispatch.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Start the background process, continue launching the other lanes, then drain the
8080

8181
The runner and its preflight have no implicit timeout. Do not invent a duration from role, mode, or a convenient round number; real implementation lanes can run for 90 minutes or much longer. Pass `--timeout` only when the user, an external service deadline, or a measured task contract supplies a real bound. That value starts at wrapper entry, before module loading and argument parsing, and remains one absolute deadline across setup, preflight, model execution, and output capture. It is never a fresh allowance per child, and long waits are armed in runtime-safe chunks without shortening the supplied deadline. Otherwise supervise liveness through the retained background task/session handle and cancel manually only on evidence that the run is dead. Cancel through that retained handle so the runner receives SIGINT or SIGTERM, sends it to an active child when one remains, stops waiting on inherited output pipes, removes the empty output reservation, and writes a `cancelled` receipt. Preserve that receipt; a retry is a new attempt with new unique output and receipt paths. Unchanged running state is not a dropout, and Claude's ten-minute foreground ceiling is never a reason to terminate a healthy lane.
8282

83-
Read-only mode maps to Claude plan mode with project-only settings and an explicit tool list, Codex's read-only sandbox, and Grok plan mode plus its `read-only` sandbox and read-oriented tool list. Grok's built-in read-only profile deliberately keeps its own state and system temporary directories writable, so point a read-only Grok lane at the actual checkout rather than a worktree under `/tmp`, `/var/tmp`, or the host's temporary directory. `isolated-write` maps to Claude `acceptEdits` with project-only settings, Codex `workspace-write`, and Grok `acceptEdits` plus its `workspace` sandbox, write-capable tool list, and an `--allow Bash` rule. Headless Grok cancels any tool call that would need an approval prompt and ends the turn, so the rule pre-approves shell commands. The sandbox, deny rules, and hooks still apply, and a command that reaches outside the workspace is still cancelled. Give every writer only a dedicated worktree or output directory. Never route a writer into the primary checkout.
83+
Read-only mode maps to Claude plan mode with project-only settings and an explicit tool list, Codex's read-only sandbox, and Grok plan mode plus its `read-only` sandbox and read-oriented tool list. Grok's built-in read-only profile deliberately keeps its own state and system temporary directories writable, so point a read-only Grok lane at the actual checkout rather than a worktree under `/tmp`, `/var/tmp`, or the host's temporary directory. `isolated-write` maps to Claude `acceptEdits` with project-only settings, Codex `workspace-write`, and Grok `acceptEdits` plus its `workspace` sandbox, write-capable tool list, and an `--allow Bash` rule. Headless Grok cancels any tool call that would need an approval prompt and ends the turn, so the rule pre-approves shell commands. Deny rules, hooks, and Grok's built-in sensitive-path checks still apply, and a command they gate is still cancelled. The `workspace` sandbox confines writes to the worktree, `~/.grok`, and temporary directories, but it reads the whole host and, on macOS, never blocks child-process network. The runner therefore gives a Grok writer only an allowlisted environment (paths, user, shell, locale, terminal, proxy and CA settings, and `GROK_*` and `XAI_*`), so parent tokens and agent sockets never reach its shell. Treat a Grok writer as able to read host files and reach the network, and route it only prompts and repositories you trust. Give every writer only a dedicated worktree or output directory. Never route a writer into the primary checkout.
8484

8585
Every concurrent external lane needs distinct prompt, output, and receipt paths. The launcher reserves output and receipt paths exclusively and refuses to overwrite them.
8686

‎plugins/pstack/skills/poteto-mode/scripts/runner/run.ts‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
reportedModelMatches,
1818
} from "./parse-output.ts";
1919
import type {
20+
AccessMode,
2021
Provider,
2122
ReceiptStatus,
2223
RunnerOptions,
@@ -133,10 +134,47 @@ const CLAUDE_IDENTITY = [
133134
"CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS",
134135
] as const;
135136

137+
const GROK_WRITER_ENV = new Set([
138+
"PATH",
139+
"HOME",
140+
"USER",
141+
"LOGNAME",
142+
"SHELL",
143+
"TMPDIR",
144+
"LANG",
145+
"TERM",
146+
"COLORTERM",
147+
"TZ",
148+
"HTTP_PROXY",
149+
"HTTPS_PROXY",
150+
"NO_PROXY",
151+
"ALL_PROXY",
152+
"http_proxy",
153+
"https_proxy",
154+
"no_proxy",
155+
"all_proxy",
156+
"SSL_CERT_FILE",
157+
"SSL_CERT_DIR",
158+
"NODE_EXTRA_CA_CERTS",
159+
]);
160+
161+
const GROK_WRITER_ENV_PREFIXES = ["LC_", "XDG_", "GROK_", "XAI_"] as const;
162+
163+
function grokWriterInherits(key: string): boolean {
164+
return GROK_WRITER_ENV.has(key)
165+
|| GROK_WRITER_ENV_PREFIXES.some((prefix) => key.startsWith(prefix));
166+
}
167+
136168
export function childEnvironment(
137169
provider: Provider,
170+
mode: AccessMode,
138171
source: NodeJS.ProcessEnv = process.env
139172
): NodeJS.ProcessEnv {
173+
if (provider === "grok" && mode === "isolated-write") {
174+
return Object.fromEntries(
175+
Object.entries(source).filter(([key]) => grokWriterInherits(key))
176+
);
177+
}
140178
const result = { ...source };
141179
const remove = provider === "claude"
142180
? CODEX_IDENTITY
@@ -539,7 +577,7 @@ async function executeLane(
539577
): Promise<RunResult> {
540578
const startedAt = new Date(started).toISOString();
541579
const prompt = readFileSync(options.promptPath, "utf8");
542-
const env = childEnvironment(options.provider);
580+
const env = childEnvironment(options.provider, options.mode);
543581
const executable = Bun.which(invocation.command, {
544582
PATH: env.PATH,
545583
cwd: options.cwd,

0 commit comments

Comments
 (0)