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

code-exec-fallback-266cba

Skill này làm gì

Skill này bảo AI chuyển phương pháp khi trình chạy code tích hợp liên tục thất bại. Dành cho người có tác vụ AI cần code Python chạy thành công.

Khi nào nên dùng

  • ✓Khi sandbox code thất bại hai lần liên tiếp với lỗi không rõ ràng.
  • ✓Khi các lần chạy code liên tục hết thời gian và thử lại không giúp ích.
  • ✓Khi tôi cần một script Python chạy từ dòng lệnh thay vì trong sandbox.

Liên kết skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/code-exec-fallback-266cba/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-266cba/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 code liên tục thất bại với script dữ liệu của tôi. Hãy chạy nó bằng cách khác và cho tôi xem đầu ra.”

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

Cách hoạt động

AI ghi code Python vào một tệp, chạy bằng lệnh shell, đọc đầu ra và lỗi, rồi báo cáo xem có thành công hay không.

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 Pattern

When to Use This Skill

Apply this pattern when you encounter repeated failures with execute_code_sandbox:

  • 2+ consecutive failures with opaque or unknown errors
  • Timeout errors that persist across retry attempts
  • Environment-related errors that don't resolve with code fixes

The Fallback Workflow

Step 1: Detect Repeated Failures

Track execution failures. After 2 consecutive failures with execute_code_sandbox, switch to the fallback approach.

Step 2: Write Script to File

Use write_file to save your Python script:

write_file(
    path="/workspace/script_name.py",
    content="# Your Python code here\nimport sys\n..."
)

Step 3: Execute via Shell

Use run_shell to run the script:

run_shell(
    command="python /workspace/script_name.py",
    timeout=300
)

Step 4: Capture Output

Parse stdout/stderr from run_shell output to verify success or diagnose issues.

Complete Example

# Instead of this (which may fail):
result = execute_code_sandbox(code="import pandas as pd\n...")

# Use this fallback pattern:
script_content = """
import pandas as pd
import sys

try:
    # Your logic here
    df = pd.DataFrame({'col': [1, 2, 3]})
    print(df.to_csv())
    sys.exit(0)
except Exception as e:
    print(f"ERROR: {e}", file=sys.stderr)
    sys.exit(1)
"""

# Write the script
write_file(path="/workspace/my_script.py", content=script_content)

# Execute via shell
result = run_shell(command="python /workspace/my_script.py", timeout=300)

Best Practices

  1. Add error handling in your script - use try/except with sys.exit() codes
  2. Set appropriate timeouts - run_shell default is 30s, increase for heavy operations
  3. Clean up temporary files after execution if needed
  4. Log the fallback trigger - document why you switched approaches
  5. Verify Python availability - Most sandboxes have Python 3.x by default

Why This Works

  • write_file is more reliable for file I/O operations
  • run_shell gives you direct control over execution environment
  • Shell execution bypasses sandbox serialization issues
  • Better error visibility through stdout/stderr streams

When NOT to Use This Pattern

  • First-time execution failures (retry the sandbox first)
  • Simple one-liner code (sandbox is faster)
  • When sandbox errors are clearly code bugs (fix the code instead)
  • Security-sensitive operations requiring sandbox isolation
Câu hỏi thường gặp

Thế nào là một lần thất bại?

Hướng dẫn nói đến lỗi lặp lại, lỗi không rõ hoặc hết thời gian từ sandbox.

Tôi có xem được lỗi không?

Có. Đầu ra và thông báo lỗi được ghi lại để AI báo cáo điều gì đã sai.

Vì sao phải ghi code vào tệp?

Hướng dẫn nói cách này có thể hoạt động khi sandbox đã thất bại nhiều lần.

Chi tiết

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

Fallback workflow for reliable code execution when sandbox fails repeatedly

repo: HKUDS/AgentPilot

Độ phổ biến

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