shell-python-heredoc
What it does
This skill shows the AI agent how to run a multi-line Python script through the shell when the sandbox keeps failing. It is for people whose scripts need several imports or clear error output.
When to use it
- ✓When the code sandbox has failed two or more times with unexplained errors.
- ✓When a script has several imports, such as reportlab or pandas, and is too long for one line.
- ✓When you need the stdout and stderr shown so you can see what went wrong.
Skill link
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/shell-python-heredoc/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
“Run my multi-line ReportLab script through the shell because the sandbox failed twice. Show me the output.”
5 new skills a week. 1 minute to read.
How it works
The agent wraps the script in a heredoc with a quoted end marker and runs it with python3 and a time limit. It then reads stdout and stderr to see whether the job worked.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Shell Python Heredoc (Fallback Pattern)
Overview
When execute_code_sandbox fails repeatedly (e.g., with "unknown error"), use run_shell with a Python heredoc as a reliable fallback for executing multi-line Python scripts with imports.
When to Use
execute_code_sandboxhas failed 2+ times with unexplained errors- You need to run Python code with multiple imports (e.g., ReportLab, pandas)
- The script is too complex for a one-liner but doesn't require persistence between calls
- You need better error visibility from raw stdout/stderr
How to Use
Basic Pattern
run_shell(
command="""python3 << 'EOF'
import sys
# Your Python code here
print("Hello from heredoc")
EOF""",
timeout=300
)
Key Syntax Rules
- Use
<< 'EOF'(with single quotes) to prevent shell variable expansion - Indent Python code relative to the heredoc delimiter
- End with
EOFon its own line (no leading whitespace) - Capture output from stdout/stderr for debugging
Example: Generating a PDF with ReportLab
run_shell(
command="""python3 << 'EOF'
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
c = canvas.Canvas("output.pdf", pagesize=letter)
c.drawString(100, 750, "Hello PDF")
c.save()
print("PDF created successfully")
EOF""",
timeout=300
)
Example: Multi-file Data Processing
run_shell(
command="""python3 << 'EOF'
import pandas as pd
import json
# Load and process data
df = pd.read_csv("data.csv")
summary = df.describe()
# Output results
print(summary.to_string())
with open("summary.json", "w") as f:
json.dump(summary.to_dict(), f)
print("Processing complete")
EOF""",
timeout=300
)
Advantages Over execute_code_sandbox
- More reliable for complex imports (no sandbox isolation issues)
- Full stdout/stderr access for debugging
- Longer timeout flexibility (60s default vs 30s)
- Direct filesystem access without ARTIFACT_PATH indirection
Disadvantages
- No persistent state between calls (each heredoc is a fresh process)
- Verbose for simple one-liners
- Shell escaping may be needed for complex string literals
Troubleshooting
| Issue | Solution |
|---|---|
EOF not recognized |
Ensure EOF is on its own line with no leading spaces |
| Import errors | Verify packages are installed in the shell environment |
| File not found | Use absolute paths or check working directory with pwd |
| Syntax errors | Check Python indentation within heredoc |
See Also
- Use
execute_code_sandboxfor simpler scripts when available - Use
shell_agentfor tasks requiring autonomous iteration and error recovery - Consider writing scripts to
.pyfiles for complex, reusable code
FAQ
Why must the end marker sit at the start of a line?
The shell only recognizes the end marker when it has no leading spaces.
Why use a quoted marker?
A quoted marker stops the shell from changing variables or symbols inside the Python code.
Does the script keep state between runs?
The skill says this approach is for jobs that do not need to keep state between calls.
Details
Original description by the author
Execute complex Python code via run_shell heredoc when execute_code_sandbox fails
repo: HKUDS/AgentPilot
Popularity
- GitHub stars
- 7.8k
- Ranking position
- #13002
- 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.