Execute Code Fallback logo

Execute Code Fallback

OrganizationPopular
HKUDS
execute-code-fallback

Fallback from execute_code_sandbox to run_shell when e2b sandbox is unavailable

Overview

PublisherHKUDS
RepositoryOpenSpace
Skill nameexecute-code-fallback
Stars
7.7K
Forks
918
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by HKUDS on GitHub. Read the source before you install it.

Installation

Install the Execute Code Fallback AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/HKUDS/OpenSpace.git /tmp/OpenSpace
mkdir -p .claude/skills
cp -r /tmp/OpenSpace/benchmarks/gdpval/skills/execute-code-fallback .claude/skills/execute-code-fallback
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Execute Code Fallback in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Execute Code Fallback on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Execute Code Fallback is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Execute Code Fallback Pattern

When execute_code_sandbox fails due to e2b unavailability, immediately fall back to run_shell with embedded Python code. This ensures task continuity when the sandbox service is down.

When to Apply

Use this pattern when you observe:

  • execute_code_sandbox returns errors mentioning "e2b", "sandbox unavailable", or connection timeouts
  • Repeated sandbox execution failures (2+ attempts)
  • Error messages indicating the code execution environment is unreachable

Fallback Procedure

Step 1: Detect the Failure

Identify that execute_code_sandbox has failed. Common error indicators:

  • "e2b service unavailable"
  • "Sandbox connection failed"
  • "Execution environment not reachable"
  • Timeout errors during code execution

Step 2: Switch to run_shell with Embedded Python

Instead of:

python
execute_code_sandbox(code="...")

Use:

bash
run_shell(command="python3 -c '...your Python code...'")

Step 3: Install Dependencies First (If Needed)

If your Python code requires external packages, install them first:

bash
run_shell(command="pip install pandas requests matplotlib")

Then execute your main code:

bash
run_shell(command="python3 << 'EOF'
import pandas as pd
import requests

# Your code here
print("Success")
EOF
")

Step 4: Use Heredoc for Multi-line Code

For complex Python scripts, use heredoc syntax for cleaner code:

bash
run_shell(command="python3 << 'PYTHON_SCRIPT'
import json
import os

# Complex logic here
data = {'key': 'value'}
with open('output.json', 'w') as f:
    json.dump(data, f)

print('File created successfully')
PYTHON_SCRIPT
")

Complete Example

Scenario: You need to process a CSV file and generate a report.

Original approach (sandbox):

python
execute_code_sandbox(code="""
import pandas as pd
df = pd.read_csv('data.csv')
summary = df.describe()
print(summary)
""")

Fallback approach (run_shell):

bash
# First install dependencies if needed
run_shell(command="pip install pandas --quiet")

# Then execute the code
run_shell(command="python3 << 'EOF'
import pandas as pd
df = pd.read_csv('data.csv')
summary = df.describe()
print(summary)
EOF
")

Important Considerations

  1. State Persistence: Unlike execute_code_sandbox, run_shell executions may not share state between calls. Save intermediate results to files if needed.

  2. Working Directory: Ensure you're operating in the correct directory. Use pwd to verify or include cd /path/to/workdir in your commands.

  3. Python Version: Use python3 explicitly to avoid ambiguity. Verify with python3 --version if needed.

  4. Error Handling: Check the stdout/stderr from run_shell to confirm success. Failed Python scripts will return non-zero exit codes.

  5. Security: Be cautious when embedding user-provided data into shell commands. Escape appropriately or use file-based input.

  6. Performance: For large computations, run_shell may be slower than sandbox. Consider breaking into smaller steps if timeouts occur.

Quick Reference

TaskSandbox ApproachFallback Approach
Simple calculationexecute_code_sandbox(code="print(2+2)")run_shell(command="python3 -c 'print(2+2)'")
Install + runexecute_code_sandbox(code="import pkg; ...")run_shell(command="pip install pkg && python3 -c '...'")
Multi-line scriptexecute_code_sandbox(code="...")run_shell(command="python3 << 'EOF'...EOF")
File I/Oexecute_code_sandbox(code="...")run_shell(command="python3 << 'EOF'...EOF")

Recovery Checklist

  • Confirm execute_code_sandbox failure (not a code bug)
  • Switch to run_shell immediately
  • Install required packages with pip install
  • Use heredoc for multi-line Python
  • Verify output and handle errors
  • Save intermediate results to files if multi-step

Frequently asked questions

What does the Execute Code Fallback AI skill do?

Fallback from execute_code_sandbox to run_shell when e2b sandbox is unavailable

Why use Execute Code Fallback on TypingMind?

Because you install it once and use it with any model. Execute Code Fallback is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Execute Code Fallback in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/HKUDS/OpenSpace/tree/main/benchmarks/gdpval/skills/execute-code-fallback. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Execute Code Fallback?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Execute Code Fallback?

As many as you like. As long as a model supports skills, you can use Execute Code Fallback with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Execute Code Fallback AI skill free?

Yes. It is published on GitHub by HKUDS under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇