Agent skill

Code Execution Fallback

by HKUDS in HKUDS/OpenSpace

A recovery routine for agents whose sandboxed code runner keeps failing: save the Python script to disk, then run it through the shell and read the output.

MITAuto-check passedAgent Workflows

Install Code Execution Fallback

skills CLI
$ npx skills add HKUDS/OpenSpace --skill code-exec-fallback-266cba -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install HKUDS/OpenSpace code-exec-fallback-266cba --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/HKUDS/OpenSpace.git skills-src && mkdir -p .claude/skills && cp -r skills-src/benchmarks/gdpval/skills/code-exec-fallback-266cba .claude/skills/code-exec-fallback-266cba && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
code-exec-fallback-266cba
GitHub stars
7.7k
Token cost
~652 tokens
SKILL.md length
227 words
Files
2
Skills in repo
199
Repo updated
First seen
Licence
MIT

At a glance

A recovery routine for agents whose sandboxed code runner keeps failing: save the Python script to disk, then run it through the shell and read the output.

  • Works in 4 steps: Detect Repeated Failures → Write Script to File → Execute via Shell → …
  • The code sandbox tool fails twice in a row with unclear errors
  • SKILL.md covers When to Use This Skill, The Fallback Workflow, Complete Example and Best Practices, plus 2 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

After two failures in a row from the execute_code_sandbox tool, with errors that give no clue or timeouts that persist across retries, the agent stops retrying the sandbox. It saves the Python script with write_file, runs it with run_shell using an explicit timeout such as 300 seconds, and reads stdout and stderr to see whether it worked.

The skill recommends try/except blocks that exit with a status code, longer timeouts for heavy jobs because run_shell defaults to 30 seconds, cleaning up temporary files, and noting why the switch was made. It tells the agent not to use the pattern on a first failure, for one-line snippets, for plain code bugs, or for work that needs sandbox isolation.

When your agent uses it

  • The code sandbox tool fails twice in a row with unclear errors
  • Execution timeouts keep recurring after retries
  • Environment errors persist that editing the code does not fix

Example prompts

  • “The sandbox keeps timing out on this pandas script, so run it through the shell instead.”
  • “Two sandbox runs failed with no useful error. Save the script to /workspace and execute it with a 300 second timeout.”

Requirements

  • A write_file tool and a run_shell tool in the agent runtime
  • Python 3 available in the sandbox

Workflow steps

4 steps, taken from the step headings in SKILL.md.

  1. Detect Repeated Failures
  2. Write Script to File
  3. Execute via Shell
  4. Capture Output

What it can do on your machine

Read from SKILL.md and the folder at commit 3827781. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are python).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Code Execution Fallback loads about 652 tokens when it runs. Until then it costs about 25 tokens; SKILL.md has 227 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~25
When it runs · the whole SKILL.md, loaded when a task matches
~652

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from HKUDS/OpenSpace at commit 3827781, republished under its MIT licence (© HKUDS). 227 words, ~652 tokens.

Download SKILL.mdSave it as .claude/skills/code-exec-fallback-266cba/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
code-exec-fallback-266cba
description
Fallback workflow for reliable code execution when sandbox fails repeatedly

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

python
# 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

© HKUDS, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file in benchmarks/gdpval/skills/code-exec-fallback-266cba of HKUDS/OpenSpace.

  • SKILL.md
  • .skill_id

Open the folder on GitHubat commit 3827781

Compare with similar skills

Code Execution Fallback next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Code Execution Fallback compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Code Execution Fallback this skillHKUDS/OpenSpace7.7k—~652Automated safety check: PassMIT
Robust Error Handling In Scriptsaiming-lab/MetaClaw3.5k—~225Automated safety check: PassMIT
Hns Moaiadk Dev Referencemodu-ai/moai-adk1.2k—~937Automated safety check: PassApache-2.0
Mole Bug Patternstw93/Mole69k—~2kAutomated safety check: PassGPL-3.0
CLI DeveloperJeffallan/claude-skills12k1 repos~1.2kAutomated safety check: PassMIT
Hugging Face API Tool Builderhuggingface/skills11k5 repos~1.5kAutomated safety check: PassApache-2.0

Similar skills

  • A skill your agent uses when writing shell scripts, Python automation, or any unattended batch job.

    3.5k GitHub stars~225 tokensUpdated 4 mo ago
    DevelopmentAuto-check passed
  • moai-adk-go local dev reference — version management/release process (sec 5), shell-script hook development (sec 7), build & dev commands (sec 10).

    1.2k GitHub stars~937 tokensUpdated today
    DevelopmentAuto-check passed
  • A catalog of recurring bug shapes in the Mole Mac cleaner, used to review safety-sensitive diffs for deletion safety, unbounded commands, shell traps and weak tests.

    69k GitHub stars~2k tokensUpdated today
    DevelopmentAuto-check passed
  • CLI Developer

    Jeffallan/claude-skills

    Walks through designing, building and polishing a command-line tool: user workflow and command hierarchy, implementation in commander, click, typer or cobra, completions and cross-platform testing.

    12k GitHub starsUsed in 1 repo~1.2k tokens
    DevelopmentAuto-check passed
  • Official

    Builds reusable command line scripts that fetch, enrich or process data from the Hugging Face API, aimed at chained, repeated or automated tasks.

    11k GitHub starsUsed in 5 repos~1.5k tokens
    AI & LLM EngineeringAuto-check passed
  • Shared reference for naming, function size, complexity and error handling rules that reviewer agents apply across TypeScript, Python, Go, Rust, Java, C# and Swift.

    2k GitHub starsUsed in 1 repo~1.4k tokens
    DevelopmentAuto-check passed

More from HKUDS/OpenSpace

All 199 skills in this repo
  • Walks through producing a master audio track plus stems in Python, from checking a reference file and timing sections by BPM to effects, a zip archive and final verification.

    7.7k GitHub stars~2.9k tokensUpdated 1 mo ago
    Auto-check passed
  • Handle cascading data retrieval tool failures by falling back to embedded knowledge generation

    7.7k GitHub stars~765 tokensUpdated 1 mo ago
    Auto-check passed
  • Gives an agent a workaround when its code-execution sandbox keeps failing: save the Python script to a file and run it through the shell instead.

    7.7k GitHub stars~588 tokensUpdated 1 mo ago
    Auto-check passed
  • Fallback ladder for failed sandboxed code runs, plus the habit of fixing the working directory first so generated files land in the right place.

    7.7k GitHub stars~1.1k tokensUpdated 1 mo ago
    Auto-check passed
  • Fallback workflow for executing Python code when executecodesandbox fails repeatedly

    7.7k GitHub stars~1.1k tokensUpdated 1 mo ago
    Auto-check passed
  • Generate documents with writefile when retrieval tools fail, with explicit guardrails against task context drift

    7.7k GitHub stars~2.6k tokensUpdated 1 mo ago
    Auto-check passed

Works with

Questions about Code Execution Fallback

What does Code Execution Fallback do?

A recovery routine for agents whose sandboxed code runner keeps failing: save the Python script to disk, then run it through the shell and read the output. After two failures in a row from the execute_code_sandbox tool, with errors that give no clue or timeouts that persist across retries, the agent stops retrying the sandbox. It saves the Python script with write_file, runs it with run_shell using an explicit timeout such as 300 seconds, and reads stdout and stderr to see whether it worked.

When should I use Code Execution Fallback?

Code Execution Fallback fits situations like: the code sandbox tool fails twice in a row with unclear errors; execution timeouts keep recurring after retries; environment errors persist that editing the code does not fix.

How do I install Code Execution Fallback in Claude Code?

Run `npx skills add HKUDS/OpenSpace --skill code-exec-fallback-266cba -a claude-code`. Or copy the skill folder (benchmarks/gdpval/skills/code-exec-fallback-266cba in HKUDS/OpenSpace) into .claude/skills/code-exec-fallback-266cba in your project. Claude Code loads it when a task matches its description.

How do I install Code Execution Fallback in Codex?

Run `npx skills add HKUDS/OpenSpace --skill code-exec-fallback-266cba -a codex`. Or copy the skill folder (benchmarks/gdpval/skills/code-exec-fallback-266cba in HKUDS/OpenSpace) into .agents/skills/code-exec-fallback-266cba in your project. Codex loads it when a task matches its description.

Can I use Code Execution Fallback in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add HKUDS/OpenSpace --skill code-exec-fallback-266cba -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/code-exec-fallback-266cba, .gemini/skills/code-exec-fallback-266cba, .github/skills/code-exec-fallback-266cba and .opencode/skills/code-exec-fallback-266cba in your project.

What does Code Execution Fallback need to run?

SKILL.md names no scripts, command-line tools or credentials: Code Execution Fallback is instructions for the agent only. Our summary lists: A write_file tool and a run_shell tool in the agent runtime; Python 3 available in the sandbox.

Does Code Execution Fallback access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Code Execution Fallback safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Code Execution Fallback use?

Code Execution Fallback is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Code Execution Fallback use?

About 652 tokens (SKILL.md is roughly 2.6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Code Execution Fallback?

Skills that share tags, products or a category with Code Execution Fallback: Robust Error Handling In Scripts (aiming-lab/MetaClaw, 3.5k stars), Hns Moaiadk Dev Reference (modu-ai/moai-adk, 1.2k stars), Mole Bug Patterns (tw93/Mole, 69k stars) and CLI Developer (Jeffallan/claude-skills, 12k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Code Execution Fallback?

HKUDS (a GitHub organization) maintains it in HKUDS/OpenSpace, which has 7,743 GitHub stars. The repository holds 199 skills in this directory. The repository was last updated on August 12, 2026.

Source: HKUDS/OpenSpace on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.