sandbox-fallback-execution
它能做什么
这项技能为 AI 智能体提供了一种简单的备用方案:当沙箱失败或超时时,改用 shell 运行 Python 代码。它适合希望在不使用沙箱的情况下完成一个简短 Python 任务的人。
适用场景
- ✓当代码沙箱因未知错误或超时而失败的时候。
- ✓当同一个任务中沙箱失败超过两次的时候。
- ✓当代码运行前需要安装 Python 软件包的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/sandbox-fallback-execution/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“沙箱在我的脚本上返回了未知错误。如有需要请安装 pandas,并通过 shell 运行这段代码。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会先用 pip 安装所需的软件包,然后借助 heredoc 在 shell 中运行 Python 代码。在继续之前,它会检查输出中的成功信息或错误。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Sandbox Fallback Execution
When to Use This Skill
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.
Pattern Overview
execute_code_sandbox fails → run_shell with pip install → Python heredoc execution
Step-by-Step Instructions
Step 1: Detect Sandbox Failure
Monitor for these failure indicators from execute_code_sandbox:
- Unknown or unexplained errors
- Repeated execution failures (>2 attempts)
- Timeout errors
- Environment/package availability issues
Step 2: Install Required Dependencies (If Needed)
Use run_shell to install any required Python packages:
pip install <package_name>
For multiple packages:
pip install package1 package2 package3
Step 3: Execute Python via Heredoc
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:
- Use
<< 'EOF'(quoted) to prevent shell variable expansion - Use
<< EOF(unquoted) if you need shell variable interpolation - Close with
EOFon its own line
Step 4: Verify and Iterate
- Check stdout/stderr for success indicators
- If errors persist, inspect output and adjust the script
- Capture any generated artifacts (files, outputs) for verification
Complete Example
Scenario: 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
Best Practices
- Quote the heredoc delimiter (
'EOF') to avoid unintended shell expansion of Python code - Install packages first before running the script to ensure availability
- Print status messages in your script for easier debugging
- Save outputs to files when possible for verification
- Keep scripts focused - break complex tasks into multiple heredoc executions if needed
Troubleshooting
| 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 |
Related Tools
run_shell: Execute shell commands directlyexecute_code_sandbox: Primary Python execution tool (try first)shell_agent: For more complex multi-step shell tasks
常见问题
带引号和不带引号的 EOF 有什么区别?
带引号的结束标记会阻止 shell 替换变量,而不带引号的标记则允许 shell 替换变量。
智能体会安装软件包吗?
会。如果代码需要某个软件包,这项技能要求先用 pip 安装它。
如果错误仍然存在怎么办?
这项技能要求阅读输出、调整代码,然后重新运行。
详情
作者的原始描述
Fallback workflow for executing Python code when execute_code_sandbox fails
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12990
- 许可证
- 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帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。