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

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

可直接粘贴的消息

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

可以这样问 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_sandbox returns 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

  1. Include all dependencies in the script - Make the script self-contained
  2. Add error handling - Include try/except blocks to catch and report errors
  3. Use absolute or clear relative paths - Ensure file paths work in the execution context
  4. Verify prerequisites - Check that required Python packages are available
  5. 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能