sandbox-exec-fallback
它能做什么
这项技能告诉 AI 智能体从代码沙箱切换到在 shell 中运行的已保存 Python 文件。它适合用 Python 制作电子表格、数据输出或其他文件的人。
适用场景
- ✓当代码沙箱在生成电子表格或 CSV 文件时失败的时候。
- ✓当数据处理任务在沙箱中失败,而你仍需要输出结果的时候。
- ✓当较长或占用大量内存的 Python 任务需要比沙箱允许的更多时间的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/sandbox-exec-fallback/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“沙箱在制作我的开支电子表格时失败了。请把 Python 保存为文件,运行它,并确认电子表格已经生成。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会把完整的 Python 代码写入脚本文件,在 shell 中用 python3 运行并设置时间限制,然后检查打印的输出。接着,它会列出文件夹,找到脚本生成的所有文件。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Sandbox Execution Fallback
When to Use
Use this skill when execute_code_sandbox fails during Python code execution, particularly for tasks involving:
- Spreadsheet generation (xlsx, csv)
- Data processing and transformations
- File output operations
- Complex computations requiring libraries
Recovery Pattern
When execute_code_sandbox returns an error or fails to produce expected output:
Step 1: Write Python Code to File
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>
Step 2: Execute via Shell
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>
Step 3: Verify Output
Check the shell output for:
- Success messages or printed results
- Error messages (if any, diagnose and fix the script)
- File creation confirmations
Step 4: Access Generated Files
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.
Why This Works
- Same Python Environment:
python3in the shell uses the same environment as the sandbox - More Robust: Shell execution handles long-running or memory-intensive tasks better
- Debuggable: Errors are captured in stdout/stderr for easier diagnosis
- Identical Results: Produces the same output as sandbox execution when successful
Example: Spreadsheet Generation
Original 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_filewith path="generate_spreadsheet.py" and the code above as contentrun_shellwith command="python3 generate_spreadsheet.py"- Verify output.xlsx was created with
list_dir
Tips
- Increase
timeoutfor complex operations (default 30s may be insufficient) - Add explicit print statements for debugging
- Handle exceptions in your script and print error messages
- Clean up temporary script files after successful execution if needed
常见问题
输出文件放在哪里?
这项技能说明,输出文件会出现在当前工作文件夹中,因此智能体会列出该文件夹来查找它们。
脚本最长可以运行多久?
对于较长的任务,这项技能建议使用更长的超时时间,例如 300 秒。
如果脚本仍然失败怎么办?
这项技能要求阅读错误信息,修复脚本,然后重新运行。
详情
作者的原始描述
Fallback pattern for executing Python code when execute_code_sandbox fails by writing to file and running via shell
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12983
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
agentpilot
7.8k帮你的智能体准备任务并运行 AgentPilot 循环,逐步改进项目:循环会提出修改、测试修改并为其打分。
openspace
7.8k帮你的智能体设置 OpenSpace,这是一个用于存储和获取智能体技能的工具,并通过 MCP 将其连接到你的 AI 应用。
rsi-arena
7.8k帮你的智能体设置并运行标准 AI 基准测试,例如 AIME 和 Terminal-Bench,用来比较不同的改进方法。
experiment-guide
7.8k帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。