Langsung ke konten
Skillpedia
Pemrograman umum7.8k Β· #12961

python-shell-fallback

Fungsinya

Skill ini membantu agent AI memindahkan pekerjaan Python berbasis pustaka ke shell saat sandbox tidak memiliki paket yang diperlukan. Skill ini ditujukan untuk orang yang membutuhkan PDF, grafik, atau keluaran lain yang bergantung pada pustaka.

Kapan dipakai

  • βœ“Saat sandbox mengembalikan ModuleNotFoundError atau error impor serupa.
  • βœ“Saat Anda memerlukan PDF atau grafik dan sandbox tidak memiliki pustaka yang dibutuhkan.
  • βœ“Saat proses sandbox terus gagal karena masalah paket.

Link skill

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

β€œBuat laporan PDF dari teks ini. Sandbox mengatakan ada modul yang hilang, jadi jalankan di shell saja.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Agent mengenali error paket yang hilang, lalu menulis ulang kode agar berjalan di shell dengan heredoc. Lingkungan shell biasanya memiliki akses ke lebih banyak paket yang terpasang.

Konten teknis (SKILL.md asli)

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

Python Shell Fallback

When execute_code_sandbox fails for Python code that depends on external libraries, use run_shell with a heredoc Python script as a reliable fallback. The shell environment typically has better access to installed packages and system configuration than the sandbox.

When to Use This Pattern

Apply this skill when:

  • execute_code_sandbox returns errors related to missing libraries (e.g., ModuleNotFoundError)
  • The code requires packages that may not be installed in the sandbox environment
  • You need PDF generation, data visualization, or other library-heavy operations
  • Previous sandbox execution attempts have failed with import errors

How to Implement

Step 1: Identify the Failure

Check if the sandbox error indicates a library/dependency issue:

  • ModuleNotFoundError: No module named 'xxx'
  • ImportError: cannot import name 'xxx'
  • Similar package-related errors

Step 2: Convert to Shell Execution

Rewrite the code execution using run_shell with a heredoc:

python3 << 'EOF'
# Your Python code here
import library_name
# ... rest of code
EOF

Step 3: Execute via run_shell

Call run_shell with the heredoc Python script:

command: python3 << 'EOF'
import reportlab
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

# Your library-dependent code here
c = canvas.Canvas("output.pdf", pagesize=letter)
c.drawString(100, 750, "Hello World")
c.save()
EOF

Example: PDF Generation Fallback

Sandbox attempt (fails):

# execute_code_sandbox call fails with:
# ModuleNotFoundError: No module named 'reportlab'

Shell fallback (works):

python3 << 'EOF'
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

c = canvas.Canvas("legal_memo.pdf", pagesize=letter)
c.setTitle("Legal Memorandum")
c.drawString(100, 750, "CONFIDENTIAL LEGAL MEMORANDUM")
c.save()
print("PDF created successfully")
EOF

Best Practices

  1. Use quoted heredoc (<< 'EOF') - Prevents variable expansion, keeping Python code intact
  2. Verify output - Check stdout/stderr from run_shell to confirm success
  3. Handle file paths - Ensure output files are written to accessible directories
  4. Test incrementally - For complex scripts, test in smaller chunks first
  5. Include error handling - Add try/except blocks to capture issues gracefully

Alternative: Inline Python Command

For simple one-liners or short scripts:

python3 -c "import reportlab; print(reportlab.__version__)"

Troubleshooting

If shell execution also fails:

  • Check if Python3 is available: which python3
  • Verify package installation: pip3 list | grep package_name
  • Try python instead of python3 (some systems differ)
  • Consider installing the package: pip3 install package_name
Pertanyaan umum

Error apa yang menandakan agent harus beralih?

Error seperti ModuleNotFoundError atau ImportError tentang sebuah paket adalah sinyal untuk beralih.

Bisakah agent membuat file PDF?

Skill ini menyebut pembuatan PDF dengan pustaka seperti reportlab sebagai salah satu contoh.

Apakah ini selalu berhasil?

Skill ini mengasumsikan shell memiliki paketnya, jadi tetap bisa gagal jika paket tidak terpasang di sana.

Detail

Deskripsi asli dari pembuat

Fallback to shell execution when sandbox fails for library-dependent Python code

repo: HKUDS/AgentPilot

Popularitas

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

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa