Fallback pattern for executing Python code when execute_code_sandbox fails by writing to file and running via shell
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-sandbox-exec-fallback-c88912326019 ,按照其中的说明把「sandbox-exec-fallback」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Use this skill when execute_code_sandbox fails during Python code execution, particularly for tasks involving:
When execute_code_sandbox returns an error or fails to produce expected output:
Use write_file to save your Python script to a file:
# Use write_file tool with:
path: "script.py"
content: <your complete Python code as a string>
Use run_shell to execute the script:
# Use run_shell tool with:
command: "python3 script.py"
timeout: <appropriate timeout, e.g., 300 for long-running tasks>
Check the shell output for:
If the script creates output files (e.g., spreadsheets), they will be in the current working directory. Use list_dir to confirm, then read_file to access if needed.
python3 in the shell uses the same environment as the sandboxOriginal code that failed in execute_code_sandbox:
import pandas as pd
data = {'A': [1, 2, 3], 'B': [4, 5, 6]}
df = pd.DataFrame(data)
df.to_excel('output.xlsx', index=False)
print("File created successfully")
Recovery Execution:
write_file with path="generate_spreadsheet.py" and the code above as contentrun_shell with command="python3 generate_spreadsheet.py"list_dirtimeout for complex operations (default 30s may be insufficient)