Skip to content
Skillpedia
General coding7.8k · #12844

code-exec-fallback-266cba

What it does

This skill tells the AI to switch methods when its built-in code runner keeps failing. It is for people whose AI tasks need Python code to run successfully.

When to use it

  • ✓When the code sandbox fails two times in a row with unclear errors.
  • ✓When code runs keep timing out and retrying does not help.
  • ✓When I need a Python script to run from the command line instead of the sandbox.

Skill link

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

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/code-exec-fallback-266cba/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“The code runner keeps failing on my data script. Please run it another way and show me the output.”

5 new skills a week. 1 minute to read.

How it works

The AI writes the Python code into a file, runs it with a shell command, reads the output and errors, and reports whether it worked.

Technical content (original SKILL.md)

Original text by the author, straight from 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
FAQ

What counts as a failure?

The guide points to repeated errors, unknown errors or timeouts from the sandbox.

Can I see the errors?

Yes, the output and error messages are captured so the AI can report what went wrong.

Why write the code to a file?

The guide says this route can work when the sandbox has repeatedly failed.

Details

Original description by the author

Fallback workflow for reliable code execution when sandbox fails repeatedly

repo: HKUDS/AgentPilot

Popularity

GitHub stars
7.8k
Ranking position
#12844
License
MIT
Updated
11/1/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills