code-exec-fallback-266cba
它能做什么
这项技能告诉 AI,当其内置代码运行器持续失败时,应切换方法。它适合那些任务需要 Python 代码成功运行的人。
适用场景
- ✓当代码沙箱连续两次失败,且错误信息不明确的时候。
- ✓当代码运行反复超时,重试也无效的时候。
- ✓当我需要 Python 脚本从命令行运行,而不是在沙箱中运行的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/code-exec-fallback-266cba/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“代码运行器在我的数据脚本上一直失败。请换一种方式运行它,并把输出结果展示给我。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会把 Python 代码写入文件,用 shell 命令运行它,读取输出和错误信息,并汇报是否成功。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Code Execution Fallback Pattern
When to Use This Skill
Apply this pattern when you encounter repeated failures with execute_code_sandbox:
- 2+ consecutive failures with opaque or unknown errors
- Timeout errors that persist across retry attempts
- Environment-related errors that don't resolve with code fixes
The Fallback Workflow
Step 1: Detect Repeated Failures
Track execution failures. After 2 consecutive failures with execute_code_sandbox, switch to the fallback approach.
Step 2: Write Script to File
Use write_file to save your Python script:
write_file(
path="/workspace/script_name.py",
content="# Your Python code here\nimport sys\n..."
)
Step 3: Execute via Shell
Use run_shell to run the script:
run_shell(
command="python /workspace/script_name.py",
timeout=300
)
Step 4: Capture Output
Parse stdout/stderr from run_shell output to verify success or diagnose issues.
Complete Example
# Instead of this (which may fail):
result = execute_code_sandbox(code="import pandas as pd\n...")
# Use this fallback pattern:
script_content = """
import pandas as pd
import sys
try:
# Your logic here
df = pd.DataFrame({'col': [1, 2, 3]})
print(df.to_csv())
sys.exit(0)
except Exception as e:
print(f"ERROR: {e}", file=sys.stderr)
sys.exit(1)
"""
# Write the script
write_file(path="/workspace/my_script.py", content=script_content)
# Execute via shell
result = run_shell(command="python /workspace/my_script.py", timeout=300)
Best Practices
- Add error handling in your script - use try/except with
sys.exit()codes - Set appropriate timeouts -
run_shelldefault is 30s, increase for heavy operations - Clean up temporary files after execution if needed
- Log the fallback trigger - document why you switched approaches
- Verify Python availability - Most sandboxes have Python 3.x by default
Why This Works
write_fileis more reliable for file I/O operationsrun_shellgives you direct control over execution environment- Shell execution bypasses sandbox serialization issues
- Better error visibility through stdout/stderr streams
When NOT to Use This Pattern
- First-time execution failures (retry the sandbox first)
- Simple one-liner code (sandbox is faster)
- When sandbox errors are clearly code bugs (fix the code instead)
- Security-sensitive operations requiring sandbox isolation
常见问题
什么算作失败?
指南指的是沙箱反复出错、出现未知错误或超时。
我能看到错误信息吗?
可以。输出和错误信息会被记录下来,AI 可以据此说明出了什么问题。
为什么要把代码写入文件?
指南说,当沙箱反复失败时,这条路径可能行得通。
详情
作者的原始描述
Fallback workflow for reliable code execution when sandbox fails repeatedly
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12844
- 许可证
- 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帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。