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

code-exec-fallback

Fungsinya

Skill ini adalah cadangan untuk menjalankan kode Python ketika penjalan bawaan terus gagal. Skill ini cocok untuk orang yang membutuhkan skrip data atau perhitungan AI mereka tetap berjalan.

Kapan dipakai

  • ✓Saat penjalan kode gagal dua kali atau lebih karena batas, waktu habis, atau paket yang hilang.
  • ✓Saat saya membutuhkan skrip data dijalankan dari shell dengan batas waktu yang ditetapkan.
  • ✓Saat saya ingin AI membaca keluaran eksekusi dan melaporkan galat apa pun.

Link skill

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

“Penjalan Python terus kehabisan waktu pada spreadsheet saya. Bisakah Anda menyimpan skripnya ke file dan menjalankannya sebagai gantinya?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

AI menulis skrip ke file, menjalankannya dengan python3 di shell, menunggu hingga batas waktu yang ditetapkan, lalu membaca keluarannya. File tersebut bisa dihapus setelahnya.

Konten teknis (SKILL.md asli)

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

Code Execution Fallback

When to Use

Use this pattern when execute_code_sandbox fails repeatedly (typically 2+ attempts) due to environment limitations, timeouts, dependency issues, or sandbox restrictions.

The Pattern

Instead of executing code directly in the sandbox, write the Python script to a file and execute it via shell:

  1. Write the script using write_file
  2. Execute via shell using run_shell with python3 script.py
  3. Clean up (optional) remove the temporary file

Step-by-Step Instructions

Step 1: Write the Python Script

Use write_file to save your Python code:
- Path: Choose a descriptive name (e.g., "process_data.py", "analyze.py")
- Content: Your complete Python script with all imports and logic

Step 2: Execute via Shell

Use run_shell to execute:
- Command: "python3 <script_name>.py"
- Timeout: Set appropriately for your task (default 30s, increase if needed)

Step 3: Handle Output

- Capture stdout/stderr from run_shell
- Parse results as needed
- Optionally delete the script file after execution

Example

# Instead of this (which may fail):
execute_code_sandbox(code="import pandas as pd; df = pd.read_csv('data.csv')...")

# Do this:
write_file(path="analyze.py", content="""
import pandas as pd
import json

df = pd.read_csv('data.csv')
result = df.groupby('category').sum()
print(json.dumps(result.to_dict()))
""")

run_shell(command="python3 analyze.py", timeout=60)

Tips for Success

  1. Include all imports in the script file - the shell environment may differ from the sandbox
  2. Use absolute paths or ensure working directory is correct
  3. Add error handling to your script for better debugging
  4. Increase timeout for long-running operations (default is 30s)
  5. Print structured output (JSON) if you need to parse results
  6. Clean up temporary files after successful execution to avoid clutter

When This Helps

  • Sandbox has missing dependencies
  • Code execution times out in sandbox but would work in shell
  • File I/O operations are restricted in sandbox
  • Need to run external commands or system utilities
  • Complex multi-file projects that need proper file structure
Pertanyaan umum

Mengapa memakai file alih-alih penjalan?

Panduan ini menyatakan bahwa jalur ini terbukti lebih andal dalam beberapa kasus kegagalan.

Berapa batas waktu default?

Defaultnya 30 detik, dan bisa dinaikkan ketika tugas membutuhkan waktu lebih lama.

Apakah skrip membutuhkan pengaturan khusus?

Skrip sebaiknya menyertakan semua impor dan logikanya, sehingga bisa berjalan sendiri.

Detail

Deskripsi asli dari pembuat

Fallback pattern for executing Python code when execute_code_sandbox fails

repo: HKUDS/AgentPilot

Popularitas

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

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa