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

sandbox-exec-fallback

它能做什么

这项技能告诉 AI 智能体从代码沙箱切换到在 shell 中运行的已保存 Python 文件。它适合用 Python 制作电子表格、数据输出或其他文件的人。

适用场景

  • ✓当代码沙箱在生成电子表格或 CSV 文件时失败的时候。
  • ✓当数据处理任务在沙箱中失败,而你仍需要输出结果的时候。
  • ✓当较长或占用大量内存的 Python 任务需要比沙箱允许的更多时间的时候。

技能链接

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/sandbox-exec-fallback/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

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

可以这样问 AI

“沙箱在制作我的开支电子表格时失败了。请把 Python 保存为文件,运行它,并确认电子表格已经生成。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会把完整的 Python 代码写入脚本文件,在 shell 中用 python3 运行并设置时间限制,然后检查打印的输出。接着,它会列出文件夹,找到脚本生成的所有文件。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Sandbox Execution Fallback

When to Use

Use this skill when execute_code_sandbox fails during Python code execution, particularly for tasks involving:

  • Spreadsheet generation (xlsx, csv)
  • Data processing and transformations
  • File output operations
  • Complex computations requiring libraries

Recovery Pattern

When execute_code_sandbox returns an error or fails to produce expected output:

Step 1: Write Python Code to File

Use write_file to save your Python script to a file:

# Use write_file tool with:
path: "script.py"
content: <your complete Python code as a string>

Step 2: Execute via Shell

Use run_shell to execute the script:

# Use run_shell tool with:
command: "python3 script.py"
timeout: <appropriate timeout, e.g., 300 for long-running tasks>

Step 3: Verify Output

Check the shell output for:

  • Success messages or printed results
  • Error messages (if any, diagnose and fix the script)
  • File creation confirmations

Step 4: Access Generated Files

If the script creates output files (e.g., spreadsheets), they will be in the current working directory. Use list_dir to confirm, then read_file to access if needed.

Why This Works

  • Same Python Environment: python3 in the shell uses the same environment as the sandbox
  • More Robust: Shell execution handles long-running or memory-intensive tasks better
  • Debuggable: Errors are captured in stdout/stderr for easier diagnosis
  • Identical Results: Produces the same output as sandbox execution when successful

Example: Spreadsheet Generation

Original code that failed in execute_code_sandbox:

import pandas as pd

data = {'A': [1, 2, 3], 'B': [4, 5, 6]}
df = pd.DataFrame(data)
df.to_excel('output.xlsx', index=False)
print("File created successfully")

Recovery Execution:

  1. write_file with path="generate_spreadsheet.py" and the code above as content
  2. run_shell with command="python3 generate_spreadsheet.py"
  3. Verify output.xlsx was created with list_dir

Tips

  • Increase timeout for complex operations (default 30s may be insufficient)
  • Add explicit print statements for debugging
  • Handle exceptions in your script and print error messages
  • Clean up temporary script files after successful execution if needed
常见问题

输出文件放在哪里?

这项技能说明,输出文件会出现在当前工作文件夹中,因此智能体会列出该文件夹来查找它们。

脚本最长可以运行多久?

对于较长的任务,这项技能建议使用更长的超时时间,例如 300 秒。

如果脚本仍然失败怎么办?

这项技能要求阅读错误信息,修复脚本,然后重新运行。

详情

作者的原始描述

Fallback pattern for executing Python code when execute_code_sandbox fails by writing to file and running via shell

repo: HKUDS/AgentPilot

热度

GitHub 星标
7.8k
排名
#12983
许可证
MIT
更新时间
2026/11/1

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能