fallback-python-shell
What it does
This skill runs Python code directly from the shell to read files and work with data when the usual tools fail. It is for people who need documents, spreadsheets or data processed when normal tools break.
When to use it
- ✓When the code sandbox returns unknown errors on a task.
- ✓When the file reader cannot read a file in a supported format.
- ✓When I need to read a text, JSON, CSV or Excel file and process it.
Skill link
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/fallback-python-shell/SKILL.mdCopy 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
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“The file reader fails on my data file. Please use Python in the shell to read it and summarize the contents.”
5 new skills a week. 1 minute to read.
How it works
The AI runs a short Python script in a shell heredoc, which opens the file, processes the content, and prints the results back into the conversation.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Shell-Based Python Fallback
When to Use
Use this fallback pattern when:
execute_code_sandboxreturns 'unknown error'read_filereturns '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
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
- Use
python3 << 'EOF'(quoted EOF prevents variable expansion in the heredoc) - Indent Python code starting from column 0 (no extra indentation from shell)
- End with
EOFon its own line with no leading/trailing whitespace - Print results to stdout to capture them in the tool response
Common Use Cases
Reading Files (Fallback for read_file)
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
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
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
python3 << 'EOF'
from docx import Document
doc = Document('document.docx')
for para in doc.paragraphs:
print(para.text)
EOF
Data Analysis
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
Error Handling: Wrap file operations in try/except blocks
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}") EOFLarge Output: For large files, process in chunks or print summaries
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 EOFWorking Directory: Remember run_shell executes in the current working directory. Use absolute paths or ensure you're in the right directory.
Multiple Steps: Chain related operations in a single heredoc rather than multiple calls
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.
FAQ
What is a heredoc?
It is a way to send several lines of code to a shell command in one block.
Which file types are mentioned?
The guide mentions plain text, JSON, and CSV or Excel files processed with pandas.
Why print the results?
Printed output comes back into the conversation, so the AI can read and report it.
Details
Original description by the author
Use run_shell with Python heredoc when execute_code_sandbox or read_file fail
repo: HKUDS/AgentPilot
Popularity
- GitHub stars
- 7.8k
- Ranking position
- #12883
- License
- MIT
- Updated
- 11/1/2026
Comments
- …
More skills from this repository
agentpilot
7.8kHelps your agent improve a project step by step by preparing a task and running the AgentPilot loop that proposes, tests and scores changes.
openspace
7.8kHelps your agent set up OpenSpace, a tool that stores and fetches agent skills, and connect it to your AI app through MCP.
rsi-arena
7.8kHelps your agent set up and run standard AI benchmark tests, such as AIME and Terminal-Bench, to compare different improvement methods.
experiment-guide
7.8kHelps your agent plan small experiments, read their results and record findings while it investigates how to improve a program.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.