Zum Inhalt springen
Skillpedia
Allgemeines Programmieren7.8k · #12847

code-execution-fallback

Was er macht

Dieser Skill behandelt das Prüfen des Arbeitsordners vor dem Ausführen von Code und den Wechsel zur Shell-Ausführung, wenn nötig. Er richtet sich an Menschen, die von KI geschriebene Skripte ausführen und feststellen, dass Dateien am falschen Ort landen.

Wann du ihn nutzt

  • ✓Wenn Dateien während einer KI-Aufgabe immer wieder im falschen Ordner erscheinen.
  • ✓Wenn die Sandbox wiederholt scheitert und eine einfachere Version des Codes nichts ändert.
  • ✓Wenn ich möchte, dass die KI Python über die Shell ausführt, mit dem Code direkt im Befehl.

Link zum Skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/code-execution-fallback/SKILL.md

Kopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.

So nutzt du ihn

Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.

Fertige Nachricht zum Einfügen

Nutze diesen Skill, um mir zu helfen: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/code-execution-fallback/SKILL.md Lies die SKILL.md unter diesem Link und folge ihren Anweisungen für meine Aufgabe.
Soll deine KI Skills wie diesen selbst finden?Installiere den kostenlosen Skillpedia-MCP: eine Zeile, und sie durchsucht vor jeder Aufgabe 15.000+ Skills.In 1 Minute installieren →

Beispielanfrage an deine KI

“Meine KI speichert Dateien immer am falschen Ort und die Sandbox scheitert ständig. Bitte korrigiere den Ordner und starte das Skript über die Shell.”

5 neue Skills pro Woche. 1 Minute Lesezeit.

So funktioniert es

Die KI prüft zuerst ihren Arbeitsordner, probiert einfacheren Code und wechselt dann zur Shell-Ausführung, bei der der Code direkt im Befehl steht. Sie prüft die Ausgabe, um den Erfolg zu bestätigen.

Technischer Inhalt (originale SKILL.md)

Originaltext des Autors, auf Englisch, direkt von 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.txt without context
  • ❌ Repeatedly retrying failed execute_code_sandbox without 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
Häufige Fragen

Was ist ein Inline-Shell-Lauf?

Es bedeutet, dass mehrere Zeilen Python in einem Shell-Befehl in einem Block übergeben werden, statt die Sandbox zu nutzen.

Warum zuerst den Arbeitsordner prüfen?

So landen Dateien nicht an unerwarteten Orten, wenn die KI das Werkzeug wechselt.

Was kommt vor dem Wechsel zur Shell?

Die Anleitung empfiehlt, zuerst einfacheren Code zu versuchen und erst dann zur Shell-Ausführung zu wechseln, wenn es weiterhin scheitert.

Details

Originalbeschreibung des Autors

Handle code execution failures with fallback strategies and anchored workspace paths

repo: HKUDS/AgentPilot

Beliebtheit

GitHub-Sterne
7.8k
Platz im Ranking
#12847
Lizenz
MIT
Aktualisiert
1.11.2026

Ist dieser Skill nützlich?

0

Anmelden um abzustimmen.

Kommentare

  • …

Weitere Skills aus diesem Repository

Ähnliche Skills