Chuyển đến nội dung
Skillpedia
Lập trình chung7.8k · #12879

fallback-code-execution

Skill này làm gì

Skill này là cách khắc phục để chạy code Python khi sandbox liên tục thất bại với lỗi không rõ hoặc không ổn định. Dành cho người có AI chạy code phải cho ra kết quả.

Khi nào nên dùng

  • ✓Khi sandbox đã thất bại hai lần trở lên liên tiếp với cùng một code.
  • ✓Khi lỗi chung chung và gợi ý vấn đề môi trường chứ không phải lỗi trong code.
  • ✓Khi tôi muốn giữ script làm tệp để có thể kiểm tra và chạy lại.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/fallback-code-execution/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Sandbox liên tục báo lỗi chung chung với script của tôi, trong khi logic đúng. Hãy lưu nó thành tệp và chạy.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

AI ghi script vào không gian làm việc dưới một tên mô tả, cài mọi phụ thuộc trước, rồi chạy qua shell và thu thập đầu ra.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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.
Câu hỏi thường gặp

Vì sao giữ script dưới dạng tệp?

Một tệp đã lưu có thể kiểm tra, sửa và chạy lại mà không phải viết lại code.

Script được lưu ở đâu?

Trong không gian làm việc, dưới một tên mô tả kết thúc bằng .py.

Nếu cần gói thì sao?

Hướng dẫn nói nên cài chúng từ tệp requirements hoặc qua shell trước.

Chi tiết

Mô tả gốc của tác giả

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

repo: HKUDS/AgentPilot

Độ phổ biến

Sao GitHub
7.8k
Vị trí xếp hạng
#12879
Giấy phép
MIT
Cập nhật
1/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự