Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(codex): keep box-admitted custom MCP env out of Codex's shell

AdityaUmale989dc8ad158d
diff --git a/server/drivers/codex-mcp-mount.ts b/server/drivers/codex-mcp-mount.ts
index 4e09311359..9da805cd09 100644
--- a/server/drivers/codex-mcp-mount.ts
+++ b/server/drivers/codex-mcp-mount.ts
@@ -48,3 +48,8 @@ export function customServerEnvBox(
const names = [...new Set([...mounted.values()].filter((server) => configured.has(server)).flatMap((server) => Object.keys(server.env)))];
return names.length ? { box: { allowEnv: names } } : {};
}
+
+/** The custom env names the box admits into Codex: none with the box off, where its shell keeps what it inherited anyway. */
+export function boxAdmittedEnv(custom: { box?: { allowEnv: string[] } }): Set<string> {
+ return new Set(botBox.enabled() ? custom.box?.allowEnv : []);
+}
diff --git a/server/drivers/codex.test.ts b/server/drivers/codex.test.ts
index 3ede638874..517916e8a5 100644
--- a/server/drivers/codex.test.ts
+++ b/server/drivers/codex.test.ts
@@ -1345,6 +1345,19 @@ process.stdout.write(JSON.stringify({jsonrpc:'2.0',id:m.id,result})+'\\n');});`)
}
}, 20_000);
+ it("with the box on, keeps a box-admitted custom env name out of Codex's shell even when the inherited value is the same", async () => {
+ const dump = join(scratch, "box-env-shell.json"); process.env.FAKE_CODEX_DUMP = dump;
+ vi.spyOn(botBox, "enabled").mockReturnValue(true);
+ await create({ mode: "resume", environment: { HOME: scratch, CODEX_HOME: join(scratch, ".codex"), FAKE_CODEX_MCP_OVERRIDES: "1", MY_MCP_AUTH: "same-fixture" } });
+ const woo = { command: "python3", args: ["woo.py"], env: { MY_MCP_AUTH: "same-fixture" } };
+ const { turnId } = await instance.adapter.sendTurn({ threadId: "t-box-env-shell", text: "go", integrations: { custom: { woo } } });
+ await recorder.until((event) => event.type === "turn.completed" && event.turnId === turnId);
+ const seen = JSON.parse(readFileSync(dump, "utf8"));
+ expect(seen.argv).toContain("features.shell_snapshot=false");
+ const thread = seen.calls.find((call: { method: string }) => call.method === "thread/start");
+ expect(thread.params.config["shell_environment_policy.exclude"]).toContain("MY_MCP_AUTH");
+ });
+
it("reaches a url server through OpenMausBot's connector on Codex's own login, header values off argv", async () => {
await create();
const dump = join(scratch, "remote-mcp.json");
diff --git a/server/drivers/codex.ts b/server/drivers/codex.ts
index 791c000a5d..5b4d046590 100644
--- a/server/drivers/codex.ts
+++ b/server/drivers/codex.ts
@@ -5,7 +5,7 @@ import { codexToolSurfaceArgs } from "./codex-tool-surface.ts";
import { codexShellDisabled, GUEST_CONFINED_CODEX_ARGS } from "./codex-guest.ts";
import { TEAM_TOOLS_FAILED, teamToolsFailed } from "./team-tools.ts";
import { enabledMcpMounts, mcpStartupTracker, supportsMcpStartup } from "./codex-mcp-startup.ts";
-import { boxProxyEnvNames, customServerEnvBox, type McpApprovalMode, mountMcpServer } from "./codex-mcp-mount.ts";
+import { boxAdmittedEnv, boxProxyEnvNames, customServerEnvBox, type McpApprovalMode, mountMcpServer } from "./codex-mcp-mount.ts";
import { reportUnsupportedCalls, rolloutMark, type RolloutMark } from "./codex-unsupported-calls.ts";
// The `codex` CLI headless over its app-server JSON-RPC (NDJSON on stdio): completion is
// `turn/completed`, approvals arrive as server→client requests, resumeCursor is the codex thread id.
@@ -633,10 +633,10 @@ export const CodexDriver: ProviderDriver<CodexConfig> = {
}
}
- // Codex gives MCP children their variables from the environment it runs shell commands in, so
- // every variable a mount writes is excluded from that shell (snapshots are off).
+ // Codex hands MCP children its shell environment, so mounted variables (and box-admitted custom env) leave that shell.
+ const customBox = customServerEnvBox(turn.integrations?.custom, selectedMcp), boxAdmitted = boxAdmittedEnv(customBox);
const mountedEnv = [...mountedNames].filter((name) => env[name] !== undefined && !SHELL_ESSENTIALS.has(name) && !name.startsWith("LC_")
- && (name === "ELECTRON_RUN_AS_NODE" || baseEnv.get(name) !== env[name]));
+ && (name === "ELECTRON_RUN_AS_NODE" || boxAdmitted.has(name) || baseEnv.get(name) !== env[name]));
const privateEnv = [...new Set([
...(config.endpoint ? ["OPENMAUSBOT_CODEX_API_KEY"] : []),
...(turn.toolScope !== undefined ? ["OMB_GATE_CONFIG_*"] : []),
@@ -659,7 +659,7 @@ export const CodexDriver: ProviderDriver<CodexConfig> = {
const child = spawnHoldingSlot(releaseSlot, () => spawnCli(...codexLaunch(config.cli, appServerArgs), {
cwd: turn.cwd ?? homedir(),
env,
- stdio: ["pipe", "pipe", "pipe"], ...customServerEnvBox(turn.integrations?.custom, selectedMcp),
+ stdio: ["pipe", "pipe", "pipe"], ...customBox,
}, "bot"));
let abandoned = false;