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

code-exec-fallback-266cba

Fungsinya

Skill ini memberi tahu AI untuk berganti metode ketika penjalan kode bawaannya terus gagal. Skill ini cocok untuk orang yang tugas AI-nya membutuhkan kode Python yang berjalan dengan sukses.

Kapan dipakai

  • ✓Saat sandbox kode gagal dua kali berturut-turut dengan galat yang tidak jelas.
  • ✓Saat eksekusi kode terus kehabisan waktu dan mencoba ulang tidak membantu.
  • ✓Saat saya membutuhkan skrip Python dijalankan dari baris perintah, bukan dari sandbox.

Link skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/code-exec-fallback-266cba/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/code-exec-fallback-266cba/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

“Penjalan kode terus gagal pada skrip data saya. Tolong jalankan dengan cara lain dan tunjukkan hasilnya kepada saya.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

AI menulis kode Python ke dalam file, menjalankannya dengan perintah shell, membaca keluaran dan galatnya, lalu melaporkan apakah berhasil.

Konten teknis (SKILL.md asli)

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

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
Pertanyaan umum

Apa yang dihitung sebagai kegagalan?

Panduan ini mengacu pada galat berulang, galat yang tidak diketahui, atau kehabisan waktu dari sandbox.

Bisakah saya melihat galatnya?

Bisa. Keluaran dan pesan galat direkam sehingga AI bisa melaporkan apa yang salah.

Mengapa kode ditulis ke file?

Panduan ini menyatakan bahwa jalur ini bisa berhasil ketika sandbox terus gagal.

Detail

Deskripsi asli dari pembuat

Fallback workflow for reliable code execution when sandbox fails repeatedly

repo: HKUDS/AgentPilot

Popularitas

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

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa