sandbox-execution-fallback-717e65
它能做什么
这项技能帮助 AI 智能体从持续失败的代码沙箱,转为在 shell 中运行已保存的脚本文件。它适合沙箱不稳定或经常超时的人。
适用场景
- ✓当代码沙箱在两到三次重试后再次失败的时候。
- ✓当错误指向服务问题,而不是你代码中的缺陷的时候。
- ✓当涉及文件读写的复杂代码需要更清晰的错误信息的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/sandbox-execution-fallback-717e65/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“代码沙箱一直在我的数据任务上超时。请把它写成脚本,并从 shell 运行,让我能看到错误信息。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会把 Python 代码写入文件,并在需要时把较大的任务拆分成几个文件。它通过 shell 运行脚本,读取输出和错误信息,以决定下一步。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Sandbox Execution Fallback
When to Use
Apply this pattern when execute_code_sandbox fails repeatedly or exhibits instability. Common triggers include:
- Sandbox returns errors after 2-3 retry attempts
- Error messages indicate provider/system issues rather than code bugs
- Execution times out or hangs inconsistently
- Complex multi-step code with file I/O is needed
- Better error visibility and debugging is required
Procedure
Step 1: Detect When to Switch
Recognize the failure pattern:
execute_code_sandboxproduces repeated errors despite code corrections- Error output suggests infrastructure issues (not syntax/logic errors)
- The sandbox environment appears unstable or limited
Step 2: Write Python Script to File
Use write_file to save your script:
write_file(
path="script.py",
content="#!/usr/bin/env python3
# Your Python code here
import sys
print('Executing via file-based approach')
# ... rest of your code
"
)
For multi-file projects, write each file separately:
write_file(path="utils.py", content="# Utility functions\ndef helper(): ...")
write_file(path="main.py", content="from utils import helper\nhelper()")
Step 3: Execute via Shell
Run the script using run_shell:
run_shell(command="python3 script.py")
For scripts in subdirectories:
run_shell(command="cd mydir && python3 script.py")
Step 4: Handle Output and Clean Up
- Parse stdout/stderr from
run_shelloutput - Inspect created files directly using
read_fileif needed - Remove temporary scripts after successful execution:
run_shell(command="rm script.py")
Advantages Over Sandbox Execution
| Benefit | Explanation |
|---|---|
| Bypasses provider limitations | No sandbox resource constraints |
| Better error visibility | Full stack traces and system errors |
| Environment control | Direct access to system Python and packages |
| Multi-file support | Easy imports and module structure |
| Persistence | Files remain for inspection and debugging |
| Reliability | More consistent execution behavior |
Complete Example
# Scenario: execute_code_sandbox failing on data processing task
# Step 1: Write the script
write_file(
path="process_data.py",
content="#!/usr/bin/env python3
import json
import csv
# Load and process data
with open('input.json', 'r') as f:
data = json.load(f)
# Transform data
results = []
for item in data:
results.append({'processed': item['value'] * 2})
# Write output
with open('output.csv', 'w', newline='') as f:
writer = csv.DictWriter(f, fieldnames=['processed'])
writer.writeheader()
writer.writerows(results)
print('Processing complete')
"
)
# Step 2: Execute via shell
run_shell(command="python3 process_data.py")
# Step 3: Read results
read_file(filetype="csv", file_path="output.csv")
# Step 4: Clean up (optional)
run_shell(command="rm process_data.py")
Best Practices
- Use absolute or clear relative paths - Avoid ambiguity in file locations
- Add error handling in scripts - Catch exceptions and print meaningful messages
- Validate script content before writing - Ensure proper Python syntax
- Log execution steps - Track what was written and executed for debugging
- Clean up temporary files - Remove scripts after use unless needed for later inspection
Troubleshooting
| Issue | Solution |
|---|---|
python3 not found |
Try python or specify full path /usr/bin/python3 |
| Import errors | Use run_shell(command="pip3 install package") first |
| Permission denied | Add execute permission: run_shell(command="chmod +x script.py") |
| Working directory issues | Use absolute paths or cd in the command |
常见问题
我怎么知道问题出在沙箱上?
这项技能指出,当错误表明是基础设施问题(例如反复失败或超时),而非代码错误时,就应切换。
任务可以使用多个文件吗?
可以。这项技能要求分别写入每个文件,然后运行导入其他文件的主文件。
位于子文件夹中的脚本可以运行吗?
可以。这项技能展示了在运行脚本前先切换到子文件夹。
详情
作者的原始描述
Fallback from execute_code_sandbox to file-based run_shell execution when sandbox fails
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12985
- 许可证
- 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帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。