From 72b16b3a24e09da1096a3e59dc6a4cf4d438c3b5 Mon Sep 17 00:00:00 2001 From: Gal Zahavi <38544478+galz10@users.noreply.github.com> Date: Mon, 20 Oct 2025 17:14:27 -0700 Subject: [PATCH] fix(core): Handle PTY spawn errors in macOS sandbox (#11539) --- .../utils/sandbox-macos-permissive-open.sb | 4 ++- .../src/services/shellExecutionService.ts | 33 ++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/packages/cli/src/utils/sandbox-macos-permissive-open.sb b/packages/cli/src/utils/sandbox-macos-permissive-open.sb index 50d21a1f35..2874e963ff 100644 --- a/packages/cli/src/utils/sandbox-macos-permissive-open.sb +++ b/packages/cli/src/utils/sandbox-macos-permissive-open.sb @@ -22,4 +22,6 @@ (literal "/dev/stdout") (literal "/dev/stderr") (literal "/dev/null") -) \ No newline at end of file + (literal "/dev/ptmx") + (regex #"^/dev/ttys[0-9]*$") +) diff --git a/packages/core/src/services/shellExecutionService.ts b/packages/core/src/services/shellExecutionService.ts index f3bdddbc55..d5dc17bb14 100644 --- a/packages/core/src/services/shellExecutionService.ts +++ b/packages/core/src/services/shellExecutionService.ts @@ -678,19 +678,28 @@ export class ShellExecutionService { return { pid: ptyProcess.pid, result }; } catch (e) { const error = e as Error; - return { - pid: undefined, - result: Promise.resolve({ - error, - rawOutput: Buffer.from(''), - output: '', - exitCode: 1, - signal: null, - aborted: false, + if (error.message.includes('posix_spawnp failed')) { + onOutputEvent({ + type: 'data', + chunk: + '[GEMINI_CLI_WARNING] PTY execution failed, falling back to child_process. This may be due to sandbox restrictions.\n', + }); + throw e; + } else { + return { pid: undefined, - executionMethod: 'none', - }), - }; + result: Promise.resolve({ + error, + rawOutput: Buffer.from(''), + output: '', + exitCode: 1, + signal: null, + aborted: false, + pid: undefined, + executionMethod: 'none', + }), + }; + } } }