@@ -140,8 +140,25 @@ def run_claude_code_in_sandbox(
140140 config = verify_process .stdout .read ()[:500 ],
141141 )
142142
143+ # Test Claude CLI works at all
144+ print ("[SANDBOX] Testing claude --version" , flush = True )
145+ logfire .info ("run_claude_code_in_sandbox: testing claude --version" )
146+ version_check = sb .exec ("claude" , "--version" )
147+ version_check .wait ()
148+ version_stdout = version_check .stdout .read ()
149+ version_stderr = version_check .stderr .read ()
150+ print (f"[SANDBOX] claude --version: stdout={ version_stdout } , stderr={ version_stderr } , rc={ version_check .returncode } " , flush = True )
151+ logfire .info (
152+ "run_claude_code_in_sandbox: claude --version result" ,
153+ stdout = version_stdout [:200 ] if version_stdout else None ,
154+ stderr = version_stderr [:500 ] if version_stderr else None ,
155+ returncode = version_check .returncode ,
156+ )
157+
143158 # Run Claude Code with the question
144159 # --dangerously-skip-permissions: auto-accept permission prompts (required for non-interactive)
160+ # --max-turns: limit execution to prevent runaway
161+ print ("[SANDBOX] Starting claude CLI with question" , flush = True )
145162 logfire .info ("run_claude_code_in_sandbox: starting claude CLI" )
146163 process = sb .exec (
147164 "claude" ,
@@ -151,9 +168,12 @@ def run_claude_code_in_sandbox(
151168 "stream-json" ,
152169 "--verbose" ,
153170 "--dangerously-skip-permissions" ,
171+ "--max-turns" ,
172+ "10" ,
154173 "--allowedTools" ,
155174 "mcp__policyengine__*,Bash,Read,Grep,Glob,Write,Edit" ,
156175 )
176+ print ("[SANDBOX] claude CLI process started" , flush = True )
157177 logfire .info ("run_claude_code_in_sandbox: claude CLI process started, returning" )
158178
159179 return sb , process
0 commit comments