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

sandbox-fallback-execution

Skill này làm gì

Skill này cho AI agent một phương án dự phòng đơn giản cho mã Python khi sandbox lỗi hoặc hết giờ. Nó dành cho những người cần hoàn thành một công việc Python ngắn mà không dùng sandbox.

Khi nào nên dùng

  • ✓Khi sandbox mã lỗi không rõ nguyên nhân hoặc hết giờ.
  • ✓Khi sandbox đã lỗi hơn hai lần cho cùng một công việc.
  • ✓Khi một gói Python cần được cài trước khi mã có thể chạy.

Liên kết skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/sandbox-fallback-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/sandbox-fallback-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 báo lỗi không rõ nguyên nhân với script của tôi. Hãy cài pandas nếu cần và chạy mã qua shell.”

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

Cách hoạt động

Agent cài mọi gói cần thiết bằng pip, rồi chạy mã Python qua shell bằng heredoc. Nó kiểm tra đầu ra để tìm thông báo thành công hoặc lỗi trước khi đi tiếp.

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 Fallback Execution

When to Use This Skill

Use this pattern when execute_code_sandbox fails with unknown errors, timeouts, or persistent execution failures. This fallback bypasses sandbox restrictions by using run_shell with a Python heredoc script.

Pattern Overview

execute_code_sandbox fails → run_shell with pip install → Python heredoc execution

Step-by-Step Instructions

Step 1: Detect Sandbox Failure

Monitor for these failure indicators from execute_code_sandbox:

  • Unknown or unexplained errors
  • Repeated execution failures (>2 attempts)
  • Timeout errors
  • Environment/package availability issues

Step 2: Install Required Dependencies (If Needed)

Use run_shell to install any required Python packages:

pip install <package_name>

For multiple packages:

pip install package1 package2 package3

Step 3: Execute Python via Heredoc

Run Python code using a heredoc script with run_shell:

python3 << 'EOF'
# Your Python code here
import sys
print("Hello from fallback execution")
EOF

Key heredoc syntax notes:

  • Use << 'EOF' (quoted) to prevent shell variable expansion
  • Use << EOF (unquoted) if you need shell variable interpolation
  • Close with EOF on its own line

Step 4: Verify and Iterate

  • Check stdout/stderr for success indicators
  • If errors persist, inspect output and adjust the script
  • Capture any generated artifacts (files, outputs) for verification

Complete Example

Scenario: Need to create a Word document but execute_code_sandbox keeps failing.

# Step 1: Install required package
pip install python-docx

# Step 2: Execute Python script via heredoc
python3 << 'EOF'
from docx import Document

doc = Document()
doc.add_heading('Proposal Document', 0)
doc.add_paragraph('This is the proposal content.')
doc.save('proposal.docx')
print("Document created successfully")
EOF

Best Practices

  1. Quote the heredoc delimiter ('EOF') to avoid unintended shell expansion of Python code
  2. Install packages first before running the script to ensure availability
  3. Print status messages in your script for easier debugging
  4. Save outputs to files when possible for verification
  5. Keep scripts focused - break complex tasks into multiple heredoc executions if needed

Troubleshooting

Issue Solution
pip not found Try pip3 or python3 -m pip install
Script hangs Add timeout to run_shell command
Permission errors Check file paths are writable
Import errors Verify package was installed successfully

Related Tools

  • run_shell: Execute shell commands directly
  • execute_code_sandbox: Primary Python execution tool (try first)
  • shell_agent: For more complex multi-step shell tasks
Câu hỏi thường gặp

Khác nhau giữa EOF có dấu nháy và không có dấu nháy là gì?

Dấu kết thúc có nháy ngăn shell thay đổi biến, còn dấu không có nháy cho phép shell điền giá trị vào.

Agent có cài gói không?

Có, nếu mã cần một gói, skill yêu cầu cài bằng pip trước.

Nếu vẫn còn lỗi thì sao?

Skill yêu cầu đọc đầu ra, chỉnh sửa mã và chạy lại.

Chi tiết

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

Fallback workflow 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
#12990
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ự