code-execution-fallback
Fungsinya
Skill ini mencakup pemeriksaan folder kerja sebelum kode dijalankan, dan beralih ke eksekusi shell jika diperlukan. Skill ini cocok untuk orang yang menjalankan skrip yang ditulis AI dan menemukan file tersimpan di tempat yang salah.
Kapan dipakai
- โSaat file terus muncul di folder yang salah selama tugas AI.
- โSaat sandbox gagal berulang kali dan versi kode yang lebih sederhana tidak memperbaikinya.
- โSaat saya ingin AI menjalankan Python melalui shell, dengan kode ditulis secara inline.
Link skill
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/code-execution-fallback/SKILL.mdSalin 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
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
โAI saya terus menyimpan file di tempat yang salah dan sandbox terus gagal. Tolong perbaiki folder dan jalankan skripnya dari shell.โ
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
AI pertama-tama memeriksa folder kerjanya, mencoba kode yang lebih sederhana, lalu beralih ke eksekusi shell dengan kode yang ditulis secara inline. AI memeriksa keluaran untuk memastikan eksekusi berhasil.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
Code Execution Fallback & Workspace Anchoring
This skill provides a robust pattern for executing code when the primary method fails, combined with proper workspace path management to prevent file location errors.
Core Techniques
1. Workspace Path Anchoring
Always establish and verify your working directory at the start of any task:
# At the beginning of any code execution
import os
workspace_path = os.getcwd()
print(f"Working directory: {workspace_path}")
# In shell scripts
pwd
echo "Current directory: $(pwd)"
Why: Prevents files from being written to unexpected locations when agents switch between tools.
2. Execution Fallback Ladder
When execute_code_sandbox fails, follow this escalation pattern:
Level 1: Retry with Simpler Code
- Simplify the code structure
- Remove complex dependencies
- Add explicit error handling
Level 2: Use run_shell with Heredoc
When sandbox execution repeatedly fails, switch to shell execution:
python3 << 'EOF'
import os
import pandas as pd
# Your code here
data = {"col1": [1, 2, 3], "col2": ["a", "b", "c"]}
df = pd.DataFrame(data)
df.to_csv("output.csv", index=False)
print("File written successfully")
EOF
Key points:
- Use
<< 'EOF'(quoted) to prevent variable expansion - Include all imports and dependencies inline
- Add explicit success/failure messages
Level 3: Delegate to shell_agent
For complex multi-step tasks with error recovery needs:
Task: Create a data processing pipeline that reads CSV, transforms data, and outputs Excel
Requirements:
- Handle missing values
- Apply transformations
- Write to ./output/ directory
- Retry on transient errors
3. Explicit Path Management
Always use absolute or explicitly relative paths:
# BAD - relies on implicit working directory
df.to_csv("output/data.csv")
# GOOD - explicit path anchoring
import os
base_path = os.getcwd()
output_dir = os.path.join(base_path, "output")
os.makedirs(output_dir, exist_ok=True)
df.to_csv(os.path.join(output_dir, "data.csv"))
# BAD
cd some_dir && python script.py
# GOOD
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
python script.py
Decision Tree
execute_code_sandbox fails?
โโโ Yes, with syntax/import errors โ Fix code, retry Level 1
โโโ Yes, with timeout/resource errors โ Use Level 2 (run_shell heredoc)
โโโ Yes, with unknown/unclear errors โ Use Level 3 (shell_agent)
โโโ No, success โ Verify output file exists at expected path
Common Failure Scenarios & Solutions
| Error Type | Likely Cause | Recommended Fallback |
|---|---|---|
| ModuleNotFoundError | Missing packages | run_shell with pip install first |
| Timeout | Long-running operation | shell_agent with progress tracking |
| PermissionError | Wrong directory | Verify workspace path, use explicit paths |
| Unknown error | Sandbox limitations | run_shell or shell_agent |
Example: Robust File Generation
# Step 1: Anchor workspace
import os
workspace = os.getcwd()
print(f"Workspace: {workspace}")
# Step 2: Create output directory explicitly
output_path = os.path.join(workspace, "deliverables")
os.makedirs(output_path, exist_ok=True)
# Step 3: Generate content with error handling
try:
# Your generation logic here
with open(os.path.join(output_path, "report.txt"), "w") as f:
f.write("Content here")
print(f"Success: File written to {output_path}")
except Exception as e:
print(f"Error: {e}")
# Signal to escalate to run_shell or shell_agent
raise
Anti-Patterns to Avoid
- โ Assuming current directory without verification
- โ Using relative paths like
../output/file.txtwithout context - โ Repeatedly retrying failed
execute_code_sandboxwithout changing approach - โ Not checking if output files exist after generation
- โ Mixing implicit and explicit path styles in same task
Verification Checklist
After any code execution:
- Confirm working directory was verified at start
- Confirm output files exist at expected paths
- Confirm file contents are non-empty and valid
- If execution failed, escalate to next fallback level within 2 retries
Pertanyaan umum
Apa itu eksekusi shell inline?
Artinya beberapa baris Python dikirim ke satu perintah shell dalam satu blok, bukan memakai sandbox.
Mengapa folder kerja diperiksa lebih dulu?
Ini mencegah file ditulis ke tempat yang tidak terduga ketika AI berganti alat.
Apa yang dilakukan sebelum beralih ke shell?
Panduan ini menyarankan mencoba kode yang lebih sederhana terlebih dahulu, lalu beralih ke eksekusi shell jika masih gagal.
Detail
Deskripsi asli dari pembuat
Handle code execution failures with fallback strategies and anchored workspace paths
repo: HKUDS/AgentPilot
Popularitas
- Bintang GitHub
- 7.8k
- Peringkat
- #12847
- Lisensi
- MIT
- Diperbarui
- 1/11/2026
Komentar
- โฆ
Skill lain dari repositori ini
agentpilot
7.8kMembantu agent Anda meningkatkan proyek langkah demi langkah dengan menyiapkan tugas dan menjalankan loop AgentPilot yang mengusulkan, menguji, dan memberi skor pada perubahan.
openspace
7.8kMembantu agent Anda menyiapkan OpenSpace, alat yang menyimpan dan mengambil skill agent, lalu menghubungkannya ke aplikasi AI Anda melalui MCP.
rsi-arena
7.8kMembantu agent Anda menyiapkan dan menjalankan tes benchmark AI standar, seperti AIME dan Terminal-Bench, untuk membandingkan berbagai metode perbaikan.
experiment-guide
7.8kMembantu agent Anda merencanakan eksperimen kecil, membaca hasilnya, dan mencatat temuan saat menyelidiki cara memperbaiki sebuah program.
Skill serupa
diffs
394kMemungkinkan agent Anda menghasilkan diff perubahan yang nyata dan dapat dibagikan sebagai tautan viewer atau file gambar, bukan ringkasan yang ditulis manual.
coding-agent
394kMembantu agent Anda menyerahkan pekerjaan pemrograman besar ke Codex, Claude Code, atau OpenCode di latar belakang, lalu memeriksa kemajuannya.
gh-issues
394kMembantu agent Anda menemukan issue GitHub, memilih yang dikerjakan, dan membuka pull request perbaikan, termasuk tindak lanjut komentar tinjauan.