Skip to content

Commit 2b0e6de

Browse files
committed
fix(codex-cli): preserve explicit sandbox selection
1 parent 3d90899 commit 2b0e6de

2 files changed

Lines changed: 34 additions & 31 deletions

File tree

‎src/worker/adapters/codex-cli-adapter.ts‎

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,45 +57,22 @@ function buildCodexMcpOverrides(servers: McpServerConfig[]): string[] {
5757
}
5858

5959
function normalizeLegacyCodexArgs(args: string[]): string[] {
60-
let needsBypass = false;
6160
const preserved: string[] = [];
6261

6362
for (let i = 0; i < args.length; i++) {
6463
const arg = args[i]!;
6564
if (arg === "--dangerously-bypass-approvals-and-sandbox") {
66-
needsBypass = true;
65+
preserved.push(arg);
6766
continue;
6867
}
6968
if (arg === "--ask-for-approval") {
7069
const value = args[i + 1];
71-
if (value === "never") {
72-
needsBypass = true;
73-
i++;
74-
continue;
75-
}
76-
}
77-
preserved.push(arg);
78-
}
79-
80-
if (!needsBypass) {
81-
return preserved;
82-
}
83-
84-
const normalized: string[] = [];
85-
for (let i = 0; i < preserved.length; i++) {
86-
const arg = preserved[i]!;
87-
if (arg === "--full-auto") {
88-
continue;
89-
}
90-
if (arg === "--sandbox") {
91-
i++; // drop the sandbox value as well; bypass supersedes sandbox selection
70+
if (typeof value === "string") i++;
9271
continue;
9372
}
94-
normalized.push(arg);
73+
preserved.push(arg);
9574
}
96-
97-
normalized.push("--dangerously-bypass-approvals-and-sandbox");
98-
return normalized;
75+
return preserved;
9976
}
10077

10178
export class CodexCliAdapter extends BaseProcessAdapter {
@@ -163,17 +140,18 @@ export class CodexCliAdapter extends BaseProcessAdapter {
163140
task.capabilities.includes(WorkerCapability.RUN_COMMANDS) ||
164141
task.capabilities.includes(WorkerCapability.RUN_TESTS);
165142
const hasBypass = args.includes("--dangerously-bypass-approvals-and-sandbox");
143+
const hasSandbox = args.includes("--sandbox") || args.includes("-s");
144+
const hasFullAuto = args.includes("--full-auto");
166145

167146
if (hasBypass) {
168147
// Current Codex CLI bypass mode already implies no sandbox / no approvals.
169148
} else if (hasWrite && hasRunCommands) {
170149
// Low-friction sandboxed auto execution.
171-
if (!args.includes("--full-auto")) {
150+
if (!hasFullAuto && !hasSandbox) {
172151
args.push("--full-auto");
173152
}
174153
} else {
175154
// Stay sandboxed and align with capability intent.
176-
const hasSandbox = args.includes("--sandbox") || args.includes("-s");
177155
if (!hasSandbox) {
178156
args.push("--sandbox", hasWrite ? "workspace-write" : "read-only");
179157
}

‎test/unit/worker/codex-cli-adapter.test.ts‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ describe("CodexCliAdapter", () => {
152152
]);
153153
});
154154

155-
test("should include task default args from workflow-resolved profiles", () => {
155+
test("should drop unsupported approval flags while preserving explicit sandbox mode", () => {
156156
const task = createTask({
157157
capabilities: [WorkerCapability.READ],
158158
defaultArgs: ["--sandbox", "danger-full-access", "--ask-for-approval", "never"],
@@ -161,7 +161,8 @@ describe("CodexCliAdapter", () => {
161161
expect(command).toEqual([
162162
"codex",
163163
"exec",
164-
"--dangerously-bypass-approvals-and-sandbox",
164+
"--sandbox",
165+
"danger-full-access",
165166
"--json",
166167
"--cd",
167168
"/tmp/test-workspace",
@@ -251,6 +252,30 @@ describe("CodexCliAdapter", () => {
251252
expect(command).toContain("--full-auto");
252253
});
253254

255+
test("should not append full-auto when an explicit sandbox mode is already provided", () => {
256+
const task = createTask({
257+
capabilities: [
258+
WorkerCapability.READ,
259+
WorkerCapability.EDIT,
260+
WorkerCapability.RUN_COMMANDS,
261+
],
262+
defaultArgs: ["--sandbox", "danger-full-access"],
263+
});
264+
const command = adapter.buildCommand(task);
265+
266+
expect(command).toEqual([
267+
"codex",
268+
"exec",
269+
"--sandbox",
270+
"danger-full-access",
271+
"--json",
272+
"--cd",
273+
"/tmp/test-workspace",
274+
"Fix the bug in main.ts",
275+
]);
276+
expect(command).not.toContain("--full-auto");
277+
});
278+
254279
test("should set auto-edit approval mode for EDIT without RUN_COMMANDS", () => {
255280
const task = createTask({
256281
capabilities: [WorkerCapability.READ, WorkerCapability.EDIT],

0 commit comments

Comments
 (0)