Langsung ke konten
Skillpedia
Pemrograman umum7.8k · #12991

sandbox-fallback-python-e5d7ae

Fungsinya

Skill ini menjelaskan bagaimana agent AI dapat menjalankan kode Python lewat shell saat sandbox tidak dapat dimulai atau tersambung. Skill ini ditujukan untuk orang yang memakai pustaka seperti reportlab atau pandas.

Kapan dipakai

  • ✓Saat sandbox menampilkan error inisialisasi, startup, atau koneksi.
  • ✓Saat skrip pendek perlu dijalankan di shell segera.
  • ✓Saat skrip yang lebih panjang harus disimpan ke file dan dijalankan dengan batas waktu lebih lama.

Link skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/sandbox-fallback-python-e5d7ae/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/sandbox-fallback-python-e5d7ae/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit →

Contoh permintaan ke AI

“Sandbox tidak bisa dimulai. Buat faktur PDF saya dengan reportlab dengan menjalankan skrip di shell.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Untuk kode pendek, agent memakai heredoc di dalam perintah shell. Untuk kode yang lebih panjang, agent menulis skrip ke file sementara dan menjalankannya, dengan batas waktu lebih lama jika diperlukan.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Python Sandbox Fallback Pattern

When to Use

Use this pattern when execute_code_sandbox fails with e2b/sandbox initialization errors, especially when running Python code that requires external libraries like reportlab, pandas, numpy, etc.

Common Failure Indicators

Detect these error patterns to trigger the fallback:

  • e2b initialization errors
  • sandbox creation/creation timeout failures
  • container startup errors
  • Connection/refusal errors from sandbox service

The Fallback Pattern

Basic Heredoc Approach

For short scripts, use a Python heredoc directly in run_shell:

run_shell(
    command="""python3 << 'EOF'
import sys
print(f"Python version: {sys.version}")
# Your code here
EOF
""",
    timeout=60
)

File-Based Approach for Complex Scripts

For longer scripts or when you need to preserve state across multiple executions:

# Step 1: Write the script to a temporary file
script_content = '''
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
import os

# Your code here
'''

run_shell(command=f"cat > /tmp/script.py << 'SCRIPT_EOF'\n{script_content}\nSCRIPT_EOF")

# Step 2: Execute the script
result = run_shell(command="python3 /tmp/script.py", timeout=120)

Key Considerations

Timeouts

  • run_shell typically needs longer timeouts than execute_code_sandbox
  • Use timeout=60 for simple scripts
  • Use timeout=120 or higher for library-heavy operations (PDF generation, data processing)

Library Availability

  • Verify required libraries are installed in the shell environment
  • Install missing libraries first if needed:
    run_shell(command="pip install reportlab", timeout=60)
    

Error Handling

  • Capture and inspect run_shell output for Python errors
  • Check stderr for import failures or runtime exceptions

Working Directory

  • Files created via run_shell are in the current working directory by default
  • Use absolute paths or os.getcwd() to reference files reliably

Example: PDF Generation with reportlab

# FALLBACK VERSION (when execute_code_sandbox fails):

pdf_code = """
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch

def create_memo(filename):
    c = canvas.Canvas(filename, pagesize=letter)
    c.drawString(1*inch, 10*inch, "Legal Memorandum")
    c.save()
    print(f"Created {filename}")

create_memo('/workspace/output.pdf')
"""

# Write script to file
run_shell(command=f"cat > /tmp/create_pdf.py << 'PYEOF'\n{pdf_code}\nPYEOF")

# Execute and verify
run_shell(command="python3 /tmp/create_pdf.py", timeout=120)

# Verify output exists
run_shell(command="ls -la /workspace/output.pdf", timeout=30)

Comparison Table

Aspect execute_code_sandbox run_shell (fallback)
Isolation High (containerized) Low (host environment)
Reliability Can fail with e2b errors More reliable
Library Access Pre-configured sandbox Depends on host
Timeout Default 30s Configurable
File Access ARTIFACT_PATH convention Direct filesystem

Migration Checklist

When switching from execute_code_sandbox to run_shell:

  • Increase timeout values (typically 2-4x)
  • Convert ARTIFACT_PATH references to actual file paths
  • Add explicit file verification steps after execution
  • Handle potential library import errors
  • Test script execution in shell environment first
Pertanyaan umum

Mengapa memakai batas waktu yang lebih panjang?

Skill ini mencatat bahwa proses di shell biasanya memerlukan waktu lebih lama daripada proses di sandbox.

Di mana file sementara disimpan?

Contoh dalam skill ini menyimpannya di folder temp, meski agent dapat memilih lokasi lain.

Pustaka apa yang disebut?

Skill ini menyebut reportlab, pandas, dan numpy sebagai contoh pustaka yang mungkin dibutuhkan kode.

Detail

Deskripsi asli dari pembuat

Fallback to run_shell with Python heredoc when execute_code_sandbox fails

repo: HKUDS/AgentPilot

Popularitas

Bintang GitHub
7.8k
Peringkat
#12991
Lisensi
MIT
Diperbarui
1/11/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa