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

fallback-code-execution

它能做什么

这项技能是在沙箱持续出现未知或不稳定的错误时,运行 Python 代码的变通方法。它适合那些需要代码产生结果的 AI 任务的人。

适用场景

  • ✓当沙箱连续两次或以上使用同一段代码失败的时候。
  • ✓当错误很笼统,显示的是环境问题而非代码错误的时候。
  • ✓当我希望把脚本保留为文件,以便检查并再次运行的时候。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“沙箱在我的脚本上一直报笼统的错误,但逻辑是正确的。请把它保存为文件并运行。”

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

工作原理

AI 会把脚本以描述性的名称写入工作区,先安装所有依赖项,然后通过 shell 运行它,并捕获输出。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Fallback Code Execution Workflow

Overview

This skill defines a robust workaround for executing code (specifically Python) when the primary execute_code_sandbox tool fails repeatedly with unknown or transient errors. Instead of continuing to retry the failing tool, the agent switches to a manual file-write and shell-execution pattern.

Trigger Conditions

Activate this workflow when:

  1. execute_code_sandbox fails 2 or more times consecutively for the same logic.
  2. Error messages are generic, unknown, or indicate environment issues rather than syntax errors.
  3. The code logic itself is verified correct but the execution environment is unstable.

Procedure

Step 1: Write Script to File

Use the write_file tool to save the Python script to a specific path in the workspace.

  • Path: Choose a descriptive name ending in .py (e.g., scripts/generate_report.py).
  • Content: Ensure the script includes necessary error handling and print statements for debugging.
  • Dependencies: If the script requires external libraries, ensure a requirements.txt is updated or installed via shell beforehand.

Example:

tool: write_file
path: workspace/scripts/process_data.py
content: |
  import sys
  # ... script logic ...
  print("Success")

Step 2: Execute via Shell

Use the run_shell tool to execute the script using the system Python interpreter.

  • Command: python3 <path_to_script> or python <path_to_script>.
  • Working Directory: Ensure the shell command runs from the workspace root or the directory containing the script.
  • Capture Output: Store stdout and stderr for verification.

Example:

tool: run_shell
command: python3 scripts/process_data.py

Step 3: Verify Execution

  1. Check Exit Code: Ensure the shell command returned exit code 0.
  2. Check Output: Verify expected files were created or expected stdout messages appeared.
  3. Handle Errors: If the shell execution fails, inspect the stderr output. This often provides more detailed tracebacks than the sandbox tool.

Best Practices

  • Absolute Paths: When writing scripts that access files, use absolute paths or resolve paths relative to __file__ to avoid working directory issues.
  • Permissions: Ensure the workspace directory allows file creation and execution.
  • Cleanup: Optionally remove temporary scripts after successful execution if cleanliness is required.
  • Logging: Add explicit print() statements in the Python script to log progress, as shell output capture is sometimes more reliable than sandbox return values.

Example Scenario

Problem: execute_code_sandbox times out while generating a PDF. Solution:

  1. Write generate_pdf.py to workspace/scripts/.
  2. Run python3 workspace/scripts/generate_pdf.py via run_shell.
  3. Confirm output.pdf exists in the workspace.
常见问题

为什么要把脚本保存为文件?

保存的文件可以被检查、修改并再次运行,无需重写代码。

脚本保存在哪里?

保存在工作区中,使用以 .py 结尾的描述性名称。

如果需要软件包怎么办?

指南建议事先从 requirements 文件或通过 shell 安装它们。

详情

作者的原始描述

Fallback workflow for running code via file write and shell when sandbox execution fails

repo: HKUDS/AgentPilot

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能