Fallback workflow for executing Python code when execute_code_sandbox fails
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-sandbox-fallback-execution-0a7f65f1ca56 ,按照其中的说明把「sandbox-fallback-execution」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Use this pattern when execute_code_sandbox fails with unknown errors, timeouts, or persistent execution failures. This fallback bypasses sandbox restrictions by using run_shell with a Python heredoc script.
execute_code_sandbox fails → run_shell with pip install → Python heredoc execution
Monitor for these failure indicators from execute_code_sandbox:
Use run_shell to install any required Python packages:
pip install <package_name>
For multiple packages:
pip install package1 package2 package3
Run Python code using a heredoc script with run_shell:
python3 << 'EOF'
# Your Python code here
import sys
print("Hello from fallback execution")
EOF
Key heredoc syntax notes:
<< 'EOF' (quoted) to prevent shell variable expansion<< EOF (unquoted) if you need shell variable interpolationEOF on its own lineScenario: Need to create a Word document but execute_code_sandbox keeps failing.
# Step 1: Install required package
pip install python-docx
# Step 2: Execute Python script via heredoc
python3 << 'EOF'
from docx import Document
doc = Document()
doc.add_heading('Proposal Document', 0)
doc.add_paragraph('This is the proposal content.')
doc.save('proposal.docx')
print("Document created successfully")
EOF
'EOF') to avoid unintended shell expansion of Python code| Issue | Solution |
|---|---|
pip not found | Try pip3 or python3 -m pip install |
| Script hangs | Add timeout to run_shell command |
| Permission errors | Check file paths are writable |
| Import errors | Verify package was installed successfully |
run_shell: Execute shell commands directlyexecute_code_sandbox: Primary Python execution tool (try first)shell_agent: For more complex multi-step shell tasks