跳到正文
Skillpedia
通用编程7.8k · #12990

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/sandbox-fallback-execution/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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 EOF on 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

  1. Quote the heredoc delimiter ('EOF') to avoid unintended shell expansion of Python code
  2. Install packages first before running the script to ensure availability
  3. Print status messages in your script for easier debugging
  4. Save outputs to files when possible for verification
  5. 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 directly
  • execute_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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能