safe-script-execution
What it does
This skill gives the AI agent a manual way to create and run a script when its automatic tools do not produce the expected output. It is for people who want clear control over each step.
When to use it
- ✓When the code sandbox or shell agent repeatedly fails to produce the output you expected.
- ✓When you want the agent to confirm its working folder before it creates any file.
- ✓When a script contains quotes or special characters that break simpler commands.
Skill link
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/safe-script-execution/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
“My script keeps failing in the sandbox. Save it as a file with full paths, run it, and tell me if the output looks right.”
5 new skills a week. 1 minute to read.
How it works
The agent checks the current folder, writes the script to a file using a heredoc with a unique end marker, makes it executable and runs it by its full path. It then checks the output before reporting back.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Safe Script Execution Fallback
When to Use This Skill
Use this pattern when execute_code_sandbox or shell_agent repeatedly fails to produce expected outputs. This manual fallback provides explicit control over script creation and execution with built-in verification.
Step-by-Step Instructions
Step 1: Verify Working Directory
Before creating any scripts, confirm your current location and permissions:
pwd
ls -la
Document the absolute path. All subsequent file operations should use explicit paths from this point.
Step 2: Create Script via Heredoc
Use shell heredoc syntax to create scripts. This avoids issues with multi-line string escaping:
cat > /full/path/to/script.py << 'HEREDOC_END'
#!/usr/bin/env python3
# Your script content here
# Single quotes around delimiter prevent variable expansion
print("Hello from script")
HEREDOC_END
Key escaping rules:
- Use single quotes around heredoc delimiter (
'EOF') to prevent shell variable expansion - If script contains the delimiter string, choose a different unique delimiter
- For bash scripts containing special characters, escape
$, backticks, and!
Step 3: Make Executable and Run with Explicit Path
chmod +x /full/path/to/script.py
/full/path/to/script.py
Always use the full absolute path, never rely on . or relative paths.
Step 4: Verify Output
Confirm files were created and inspect their properties:
# Check file exists with size
ls -lh /full/path/to/output.file
# For PDFs, inspect metadata
pdfinfo /full/path/to/output.pdf 2>/dev/null || file /full/path/to/output.pdf
# For Word docs, check file type
file /full/path/to/output.docx
Step 5: Error Handling
If execution fails:
- Check script syntax:
python3 -m py_compile /path/to/script.py - Check permissions:
ls -l /path/to/script.py - Check available disk space:
df -h . - Review stderr output carefully
Example: PDF Generation Fallback
# Step 1: Verify directory
pwd
ls -la
# Step 2: Create Python script
cat > /workspace/generate_pdf.py << 'SCRIPT_END'
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
c = canvas.Canvas("/workspace/output.pdf", pagesize=letter)
c.drawString(100, 750, "Generated PDF")
c.save()
SCRIPT_END
# Step 3: Execute
chmod +x /workspace/generate_pdf.py
python3 /workspace/generate_pdf.py
# Step 4: Verify
ls -lh /workspace/output.pdf
pdfinfo /workspace/output.pdf 2>/dev/null || echo "PDF created, pdfinfo unavailable"
Anti-Patterns to Avoid
- ❌ Don't use relative paths like
./script.py- always use absolute paths - ❌ Don't rely on unquoted heredoc delimiters if script contains variables
- ❌ Don't skip verification steps - always confirm output exists and has expected size
- ❌ Don't assume working directory - always
pwdfirst
Troubleshooting Checklist
- Working directory confirmed with
pwd - Script file exists after heredoc creation (
ls -l) - Script has execute permissions (
chmod +x) - Output file exists with non-zero size (
ls -lh) - File type verified (
filecommand or type-specific inspection)
FAQ
Why use a full path to run the script?
A full path avoids mistakes caused by relative paths or the wrong working folder.
Why does the heredoc use a quoted end marker?
Quotes stop the shell from changing dollar signs or other symbols inside the script.
What if the script contains the end marker text?
The skill says to pick a different unique marker so the file is not cut short.
Details
Original description by the author
Fallback workflow for code execution when automated tools fail, using shell heredoc with verification
repo: HKUDS/AgentPilot
Popularity
- GitHub stars
- 7.8k
- Ranking position
- #12981
- 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.