Skip to content

Commit 72b16b3

Browse files
authored
fix(core): Handle PTY spawn errors in macOS sandbox (#11539)
1 parent 723b8d3 commit 72b16b3

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

packages/cli/src/utils/sandbox-macos-permissive-open.sb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@
2222
(literal "/dev/stdout")
2323
(literal "/dev/stderr")
2424
(literal "/dev/null")
25-
)
25+
(literal "/dev/ptmx")
26+
(regex #"^/dev/ttys[0-9]*$")
27+
)

packages/core/src/services/shellExecutionService.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -678,19 +678,28 @@ export class ShellExecutionService {
678678
return { pid: ptyProcess.pid, result };
679679
} catch (e) {
680680
const error = e as Error;
681-
return {
682-
pid: undefined,
683-
result: Promise.resolve({
684-
error,
685-
rawOutput: Buffer.from(''),
686-
output: '',
687-
exitCode: 1,
688-
signal: null,
689-
aborted: false,
681+
if (error.message.includes('posix_spawnp failed')) {
682+
onOutputEvent({
683+
type: 'data',
684+
chunk:
685+
'[GEMINI_CLI_WARNING] PTY execution failed, falling back to child_process. This may be due to sandbox restrictions.\n',
686+
});
687+
throw e;
688+
} else {
689+
return {
690690
pid: undefined,
691-
executionMethod: 'none',
692-
}),
693-
};
691+
result: Promise.resolve({
692+
error,
693+
rawOutput: Buffer.from(''),
694+
output: '',
695+
exitCode: 1,
696+
signal: null,
697+
aborted: false,
698+
pid: undefined,
699+
executionMethod: 'none',
700+
}),
701+
};
702+
}
694703
}
695704
}
696705

0 commit comments

Comments
 (0)