sandbox-execution-fallback
它能做什么
这项技能展示 AI 智能体如何通过把代码保存为 .py 文件并在 shell 中运行,来恢复失败的代码运行。它适合电子表格或数据任务在沙箱中超时的人。
适用场景
- ✓当代码沙箱在电子表格或数据任务上超时的时候。
- ✓当任务需要 pandas 或 openpyxl 等外部库的时候。
- ✓当长时间的计算不断触及沙箱时间限制的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/sandbox-execution-fallback/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的 pandas 任务在沙箱中超时。请把代码保存为文件,并在 shell 中以更长的时间限制运行它。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会取出失败的代码,用清晰的名称将其写入 .py 文件,使用系统的 Python 运行,然后检查预期的文件和结果是否已经生成。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Sandbox Execution Fallback
When to Use
Apply this pattern when execute_code_sandbox fails or times out, particularly for:
- Spreadsheet generation (pandas, openpyxl, xlsxwriter)
- Complex data processing with file I/O
- Tasks requiring external library imports
- Long-running computations that hit timeout limits
Recovery Procedure
Step 1: Capture the Python Code
Extract or reconstruct the Python code that failed in execute_code_sandbox.
Step 2: Write Code to File
Use write_file to save the script with a .py extension:
write_file(
path="script_name.py",
content="""
import pandas as pd
# Your implementation here
"""
)
Step 3: Execute via run_shell
Run the script using the system Python interpreter:
run_shell(command="python3 script_name.py")
Step 4: Verify Output
Confirm the results match expected outputs (files created, data processed correctly, etc.).
Complete Example
# Failed: execute_code_sandbox with pandas Excel generation
# Recovery - Step 1 & 2: Write script to file
write_file(
path="generate_pnl_report.py",
content="""
import pandas as pd
from openpyxl import Workbook
# Create sample data
data = {
'Category': ['Revenue', 'Expenses', 'Tax'],
'Amount': [10000, 3000, 500]
}
df = pd.DataFrame(data)
# Write to Excel
df.to_excel('pnl_report.xlsx', index=False)
print('Report generated: pnl_report.xlsx')
"""
)
# Step 3: Execute via shell
run_shell(command="python3 generate_pnl_report.py")
# Step 4: Verify file was created
run_shell(command="ls -la pnl_report.xlsx")
Why This Works
| Aspect | execute_code_sandbox | run_shell + write_file |
|---|---|---|
| Environment | Sandboxed, limited | Full system Python |
| File I/O | Restricted | Full access |
| Timeout | Strict limits | More flexible |
| Library Support | May be limited | System-installed packages |
| Result | Identical output | Identical output |
Best Practices
- Use descriptive filenames - e.g.,
generate_report.py,process_data.py - Add error handling - Include try/except blocks in your script
- Print progress - Use print statements for debugging
- Clean up - Remove temporary scripts after successful execution if needed
- Verify results - Always confirm outputs before proceeding
Common Use Cases
- Excel/CSV report generation
- Data transformation pipelines
- Batch file processing
- API data aggregation
- Chart and visualization creation
Troubleshooting
If run_shell also fails:
- Check Python is available:
run_shell(command="python3 --version") - Install missing packages:
run_shell(command="pip3 install pandas openpyxl") - Check file permissions and paths
- Review stderr output for specific errors
常见问题
如果代码丢失了,智能体能恢复吗?
这项技能要求,如果代码未曾保存,就根据失败的尝试重新构建代码。
使用哪个 Python 命令?
这项技能从 shell 中用 python3 运行脚本。
智能体如何检查是否成功?
它会确认文件已生成,且数据已按预期处理。
详情
作者的原始描述
Recover from execute_code_sandbox failures by writing Python scripts to files and executing via run_shell
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12986
- 许可证
- 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帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。