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

sandbox-execution-fallback-717e65

Skill này làm gì

Skill này giúp AI agent chuyển từ một sandbox mã liên tục lỗi sang các file script đã lưu chạy trong shell. Nó dành cho những người có sandbox không ổn định hoặc hay hết giờ.

Khi nào nên dùng

  • ✓Khi sandbox mã lỗi lại sau hai hoặc ba lần thử.
  • ✓Khi lỗi cho thấy vấn đề dịch vụ chứ không phải lỗi trong mã của bạn.
  • ✓Khi mã phức tạp có đọc và ghi file cần thông báo lỗi rõ ràng hơn.

Liên kết skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/sandbox-execution-fallback-717e65/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/sandbox-execution-fallback-717e65/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 mã liên tục hết giờ với công việc dữ liệu của tôi. Hãy viết nó thành script và chạy từ shell để tôi thấy các lỗi.”

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

Cách hoạt động

Agent ghi mã Python vào một file, và nếu cần thì tách công việc lớn thành nhiều file. Nó chạy script qua shell rồi đọc đầu ra và các lỗi để quyết định bước tiếp theo.

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.

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

Làm sao tôi biết sandbox là nguyên nhân?

Skill yêu cầu chuyển khi lỗi cho thấy sự cố hạ tầng, như lỗi lặp lại hoặc hết giờ, chứ không phải lỗi mã.

Công việc có thể dùng nhiều file không?

Có, skill yêu cầu ghi từng file riêng và chạy file chính, file này import các file khác.

Script trong thư mục con có chạy được không?

Có, skill chỉ cách chuyển vào thư mục con trước khi chạy script.

Chi tiết

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

Fallback from execute_code_sandbox to file-based run_shell execution when sandbox fails

repo: HKUDS/AgentPilot

Độ phổ biến

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