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

code-exec-fallback

Skill này làm gì

Skill này là phương án dự phòng để chạy code Python khi trình chạy tích hợp thất bại nhiều lần. Dành cho người cần script dữ liệu hoặc tính toán của AI vẫn chạy được.

Khi nào nên dùng

  • ✓Khi trình chạy code thất bại hai lần trở lên vì giới hạn, hết thời gian hoặc thiếu gói.
  • ✓Khi tôi cần một script dữ liệu chạy từ shell với giới hạn thời gian đã đặt.
  • ✓Khi tôi muốn AI đọc kết quả chạy và báo cáo mọi lỗi.

Liên kết skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/code-exec-fallback/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/code-exec-fallback/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

“Trình chạy Python liên tục hết thời gian với bảng tính của tôi. Bạn có thể lưu script vào tệp và chạy thay vì vậy không?”

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

Cách hoạt động

AI ghi script vào tệp, chạy bằng python3 trong shell, chờ tối đa một khoảng thời gian đã đặt và đọc kết quả. Tệp có thể xóa sau đó.

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.

Code Execution Fallback

When to Use

Use this pattern when execute_code_sandbox fails repeatedly (typically 2+ attempts) due to environment limitations, timeouts, dependency issues, or sandbox restrictions.

The Pattern

Instead of executing code directly in the sandbox, write the Python script to a file and execute it via shell:

  1. Write the script using write_file
  2. Execute via shell using run_shell with python3 script.py
  3. Clean up (optional) remove the temporary file

Step-by-Step Instructions

Step 1: Write the Python Script

Use write_file to save your Python code:
- Path: Choose a descriptive name (e.g., "process_data.py", "analyze.py")
- Content: Your complete Python script with all imports and logic

Step 2: Execute via Shell

Use run_shell to execute:
- Command: "python3 <script_name>.py"
- Timeout: Set appropriately for your task (default 30s, increase if needed)

Step 3: Handle Output

- Capture stdout/stderr from run_shell
- Parse results as needed
- Optionally delete the script file after execution

Example

# Instead of this (which may fail):
execute_code_sandbox(code="import pandas as pd; df = pd.read_csv('data.csv')...")

# Do this:
write_file(path="analyze.py", content="""
import pandas as pd
import json

df = pd.read_csv('data.csv')
result = df.groupby('category').sum()
print(json.dumps(result.to_dict()))
""")

run_shell(command="python3 analyze.py", timeout=60)

Tips for Success

  1. Include all imports in the script file - the shell environment may differ from the sandbox
  2. Use absolute paths or ensure working directory is correct
  3. Add error handling to your script for better debugging
  4. Increase timeout for long-running operations (default is 30s)
  5. Print structured output (JSON) if you need to parse results
  6. Clean up temporary files after successful execution to avoid clutter

When This Helps

  • Sandbox has missing dependencies
  • Code execution times out in sandbox but would work in shell
  • File I/O operations are restricted in sandbox
  • Need to run external commands or system utilities
  • Complex multi-file projects that need proper file structure
Câu hỏi thường gặp

Vì sao dùng tệp thay vì trình chạy?

Hướng dẫn nói cách này đã chứng minh đáng tin cậy hơn trong một số trường hợp lỗi.

Giới hạn thời gian mặc định là bao nhiêu?

Mặc định là 30 giây, và có thể tăng khi tác vụ cần nhiều thời gian hơn.

Script có cần thiết lập đặc biệt không?

Script nên có đầy đủ các import và logic để chạy được độc lập.

Chi tiết

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

Fallback pattern for executing Python code when execute_code_sandbox fails

repo: HKUDS/AgentPilot

Độ phổ biến

Sao GitHub
7.8k
Vị trí xếp hạng
#12845
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ự