sandbox-execution-fallback-238489
它能做什么
这项技能指导 AI 智能体在沙箱无法处理基于库的文件任务时,编写独立的 Python 脚本并运行。它适合需要 PDF、Word 文件或电子表格的人。
适用场景
- ✓当沙箱在制作 PDF、Word 或 Excel 文件时失败的时候。
- ✓当任务需要沙箱未提供的 Python 库的时候。
- ✓当你需要更多地控制脚本运行环境的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/sandbox-execution-fallback-238489/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请用 reportlab 把我的笔记制作成 PDF。沙箱失败了,所以请编写脚本文件并运行它。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会使用文件写入工具保存脚本,然后通过 shell 用 python3 运行它。它会检查脚本是否已经完成,并生成了预期的文件。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Sandbox Execution Fallback
This skill provides a reliable fallback pattern when execute_code_sandbox fails for code execution tasks (especially PDF generation, complex file operations, or library-dependent tasks).
When to Use
Use this fallback pattern when:
execute_code_sandboxreturns errors or fails to produce expected output- The task requires specific Python libraries not available in the sandbox
- File I/O operations (especially PDF, docx, xlsx) fail in the sandbox environment
- You need more control over the execution environment
Step-by-Step Instructions
Step 1: Write the Python Script to a File
Instead of executing code directly in the sandbox, use write_file to create a standalone Python script:
Use write_file to create a script (e.g., script.py) with your complete Python code.
Step 2: Execute the Script Directly
Run the script using run_shell with Python:
Use run_shell with command: python3 script.py
Step 3: Verify Output
Check that the script executed successfully and produced the expected files or output.
Example Pattern
Instead of this (sandbox execution):
execute_code_sandbox with code using libraries like reportlab, fpdf, etc.
Do this (fallback pattern):
# Step 1: Create the script
write_file:
path: generate_pdf.py
content: |
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
def create_pdf(filename):
c = canvas.Canvas(filename, pagesize=letter)
c.drawString(100, 750, "Hello World")
c.save()
create_pdf("output.pdf")
# Step 2: Execute directly
run_shell:
command: python3 generate_pdf.py
Best Practices
- Include all dependencies in the script - Make the script self-contained
- Add error handling - Include try/except blocks to catch and report errors
- Use absolute or clear relative paths - Ensure file paths work in the execution context
- Verify prerequisites - Check that required Python packages are available
- Clean up temporary files - Remove intermediate scripts after successful execution if needed
Troubleshooting
If run_shell also fails:
- Check if Python 3 is available:
run_shell command: python3 --version - Install missing packages:
run_shell command: pip3 install package_name - Check file permissions and paths
- Review error output from the shell execution for specific issues
Why This Works
This pattern bypasses sandbox limitations by:
- Running code in the actual execution environment with full library access
- Avoiding sandbox timeout or resource constraints
- Enabling direct file system access for I/O operations
- Providing better error messages from the native Python interpreter
Self-Assessment
This skill captures a genuinely reusable pattern that:
- Is generalizable beyond just PDF generation to any execute_code_sandbox failure
- Provides clear, actionable steps
- Includes example code and troubleshooting guidance
- Would benefit future executions facing similar sandbox limitations
常见问题
这涵盖哪些文件类型?
这项技能把 PDF、Word 和 Excel 文件列为在沙箱中经常失败的输出类型。
为什么要写成文件,而不是直接运行代码?
保存的脚本为 shell 提供了一个清晰的运行文件,也更便于检查工作。
智能体会确认输出吗?
会。最后一步是检查预期的文件是否已经生成。
详情
作者的原始描述
Fallback pattern for when execute_code_sandbox fails - write script to file and execute directly with run_shell
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12984
- 许可证
- 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帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。