feat: add --tty flag for interactive terminal applications#77
feat: add --tty flag for interactive terminal applications#77abe238 wants to merge 1 commit intoanthropic-experimental:mainfrom
Conversation
Detailed Technical AnalysisRoot Cause InvestigationWhen running interactive terminal applications (like Claude Code) inside This occurs because:
Code Path AnalysisThe sandbox profile generation in // Lines 585-598
if (allowPty) {
profile.push('(allow pseudo-tty)') // Master PTY permission
profile.push('(allow file-ioctl')
profile.push(' (literal "/dev/ptmx")')
profile.push(' (regex #"^/dev/ttys")') // Slave TTYs
profile.push(')')
profile.push('(allow file-read* file-write*')
profile.push(' (literal "/dev/ptmx")')
profile.push(' (regex #"^/dev/ttys")')
profile.push(')')
}The const allowPty = customConfig?.allowPty ?? config?.allowPtyHowever, there was no CLI flag to enable this option for one-off interactive commands. Why This Matters
Security ConsiderationsPTY access does NOT bypass the core sandbox restrictions:
PTY access does allow:
Alternative Solutions Considered
The CLI flag approach was chosen because:
Testing Notes
For full interactive testing, users should test with actual TUI applications like |
|
we are running into an issue using the https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk where when sandbox mode is enabled (on mac and windows users) the agent just seems to freeze up. We had to turn off sandbox mode because of it. Hopefully this PR fixes that issue and it can get merge upstream to the claude-agent-sdk |
|
Would love to see this get merged! |
Expose the existing allowPty config option via a -t/--tty CLI flag, enabling interactive TUI apps (vim, htop, Claude Code) to run inside the sandbox without EPERM errors on PTY operations. - Set allowPty on config before initialize() for clean integration - Add 4 tests covering --tty, -t, -c mode combo, and negative case - Document flag in README CLI usage and configuration reference Closes anthropic-experimental#76 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
f1f030a to
65f9aa1
Compare
|
Rebased onto latest Changes from v1:
This addresses a real pain point — multiple people in this thread and #76 have confirmed they can't run Claude Code or other TUI apps in the sandbox without this. The underlying @ollie-anthropic @ddworken — would appreciate a review when you get a chance! |

Summary
Add
-t/--ttyCLI flag to enable pseudo-terminal (PTY) passthrough for interactive terminal applications.Problem
Interactive terminal applications (like
vim,htop, Claude Code, or any TUI app) fail withsetRawMode EPERMwhen run inside the sandbox because PTY operations are blocked by default.Solution
This PR exposes the existing
allowPtyfunctionality (which already exists inSandboxRuntimeConfigandmacos-sandbox-utils.ts) via a new CLI flag:Changes
-t/--ttyflag that setsallowPty: trueon the runtime config beforeinitialize()--tty,-t,-cmode combo, and negative caseallowPtyconfig optionImplementation
The flag sets
allowPty: trueonruntimeConfigbefore callingSandboxManager.initialize(), keeping the change minimal and consistent with how other config options flow through the system. ThewrapWithSandboxcall remains unchanged.When
allowPtyis enabled, the macOS Seatbelt profile adds:(allow pseudo-tty)- Master PTY permission(allow file-ioctl (literal "/dev/ptmx") (regex #"^/dev/ttys"))- Ioctl operations on PTY devices/dev/ptmxand/dev/ttys*Testing
npm run typecheckpassesnpm run lint:checkpassesnpm run buildpasses--ttyflagSecurity Notes
Closes #76
🤖 Generated with Claude Code