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

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

可直接粘贴的消息

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

可以这样问 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_sandbox produces 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_shell output
  • Inspect created files directly using read_file if 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

  1. Use absolute or clear relative paths - Avoid ambiguity in file locations
  2. Add error handling in scripts - Catch exceptions and print meaningful messages
  3. Validate script content before writing - Ensure proper Python syntax
  4. Log execution steps - Track what was written and executed for debugging
  5. 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能