Fallback Python Shell logo

Fallback Python Shell

OrganizationPopular
HKUDS
fallback-python-shell

Use run_shell with Python heredoc when execute_code_sandbox or read_file fail

Overview

PublisherHKUDS
RepositoryOpenSpace
Skill namefallback-python-shell
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 Fallback Python Shell 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/fallback-python-shell .claude/skills/fallback-python-shell
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Fallback Python Shell 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 Fallback Python Shell 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 Fallback Python Shell 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.

Shell-Based Python Fallback

When to Use

Use this fallback pattern when:

  • execute_code_sandbox returns 'unknown error'
  • read_file returns 'unknown error' for supported formats
  • You need to process documents, analyze data, or read files programmatically

Core Technique

Run Python code through run_shell using a heredoc. This bypasses sandbox execution issues while maintaining Python's full capabilities for file I/O and data processing.

Basic Pattern

bash
python3 << 'EOF'
# Your Python code here
import json
import os

# Example: Read and process a file
with open('/path/to/file.txt', 'r') as f:
    content = f.read()
    print(content)
EOF

Key Syntax Points

  1. Use python3 << 'EOF' (quoted EOF prevents variable expansion in the heredoc)
  2. Indent Python code starting from column 0 (no extra indentation from shell)
  3. End with EOF on its own line with no leading/trailing whitespace
  4. Print results to stdout to capture them in the tool response

Common Use Cases

Reading Files (Fallback for read_file)

bash
python3 << 'EOF'
import json

# Read text file
with open('document.txt', 'r') as f:
    content = f.read()
    print(content)

# Read JSON file
with open('data.json', 'r') as f:
    data = json.load(f)
    print(json.dumps(data, indent=2))
EOF

Processing Excel/CSV Files

bash
python3 << 'EOF'
import pandas as pd

# Read Excel file
df = pd.read_excel('data.xlsx', sheet_name='Sheet1')
print(df.to_string())
print(f"Shape: {df.shape}")

# Read CSV
df = pd.read_csv('data.csv')
print(df.head(10))
EOF

Reading PDF Files

bash
python3 << 'EOF'
import fitz  # PyMuPDF

doc = fitz.open('document.pdf')
for page_num in range(len(doc)):
    page = doc[page_num]
    text = page.get_text()
    print(f"=== Page {page_num + 1} ===")
    print(text)
doc.close()
EOF

Reading Word Documents

bash
python3 << 'EOF'
from docx import Document

doc = Document('document.docx')
for para in doc.paragraphs:
    print(para.text)
EOF

Data Analysis

bash
python3 << 'EOF'
import pandas as pd
import numpy as np

df = pd.read_csv('data.csv')

# Basic statistics
print(f"Shape: {df.shape}")
print(f"Columns: {list(df.columns)}")
print(df.describe())

# Filter and aggregate
result = df.groupby('category').agg({'value': 'sum'})
print(result)
EOF

Best Practices

  1. Error Handling: Wrap file operations in try/except blocks

    bash
    python3 << 'EOF'
    try:
        with open('file.txt', 'r') as f:
            content = f.read()
            print(content)
    except FileNotFoundError:
        print("ERROR: File not found")
    except Exception as e:
        print(f"ERROR: {e}")
    EOF
  2. Large Output: For large files, process in chunks or print summaries

    bash
    python3 << 'EOF'
    with open('large_file.csv', 'r') as f:
        for i, line in enumerate(f):
            if i < 10:
                print(line.strip())
            else:
                print("... truncated ...")
                break
    EOF
  3. Working Directory: Remember run_shell executes in the current working directory. Use absolute paths or ensure you're in the right directory.

  4. Multiple Steps: Chain related operations in a single heredoc rather than multiple calls

    bash
    python3 << 'EOF'
    # Do all related work in one call
    with open('input.json') as f:
        data = json.load(f)
    
    processed = [transform(x) for x in data]
    
    with open('output.json', 'w') as f:
        json.dump(processed, f)
    
    print("Processing complete")
    EOF

Troubleshooting

  • Module not found: Some packages may not be available. Stick to standard library or commonly pre-installed packages (pandas, numpy are often available).
  • Permission errors: Ensure files aren't in protected directories.
  • Character encoding: Specify encoding explicitly: open('file.txt', 'r', encoding='utf-8')
  • Very long code: Split into multiple heredocs or write to a temporary .py file first.

Frequently asked questions

What does the Fallback Python Shell AI skill do?

Use run_shell with Python heredoc when execute_code_sandbox or read_file fail

Why use Fallback Python Shell on TypingMind?

Because you install it once and use it with any model. Fallback Python Shell 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 Fallback Python Shell in TypingMind?

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

Which AI models can use Fallback Python Shell?

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 Fallback Python Shell?

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

Is the Fallback Python Shell 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 👇