run-shell-python-file-io
What it does
This skill shows the AI agent how to do file reading, changing and writing with Python run in the shell. It is for people whose sandbox cannot see the files in their working folder.
When to use it
- ✓When the code sandbox cannot access files in your working folder.
- ✓When you need to read a file, change its text and save the result.
- ✓When a longer file job needs a temporary Python script to run more steps.
Skill link
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/run-shell-python-file-io/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
“Read input.txt in my working folder, convert the text to capitals, and save it as output.txt. The sandbox cannot see the folder.”
5 new skills a week. 1 minute to read.
How it works
The agent runs a short Python program in the shell that reads the input file, processes its text and writes the output file. It prints the working directory and a completion message so you can confirm the result.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Run Shell Python File I/O
When to Use This Skill
Use this technique when execute_code_sandbox cannot access files in your working directory, but you need to perform file operations (read, write, transform) as part of your task execution.
The Pattern
Instead of using execute_code_sandbox, run Python code directly through run_shell with explicit path handling. This provides reliable file I/O capabilities within the task workspace.
How to Apply
Step 1: Identify File Access Needs
Determine which files you need to read from or write to in the working directory.
Step 2: Write Inline Python via run_shell
Construct a Python script that handles your file operations and execute it through run_shell:
python3 -c "
import os
# Get the working directory
work_dir = os.getcwd()
print(f'Working directory: {work_dir}')
# Read a file
with open('input.txt', 'r') as f:
content = f.read()
# Process the content
processed = content.upper()
# Write to output file
with open('output.txt', 'w') as f:
f.write(processed)
print('File operation complete')
"
Step 3: Handle Complex Logic
For more complex operations, write a temporary Python script file first:
cat > /tmp/process.py << 'EOF'
import os
import json
work_dir = os.getcwd()
# Read input
with open('data.json', 'r') as f:
data = json.load(f)
# Transform
result = {k: v * 2 for k, v in data.items()}
# Write output
with open('result.json', 'w') as f:
json.dump(result, f, indent=2)
print(f'Processed {len(data)} items')
EOF
python3 /tmp/process.py
Step 4: Verify File Operations
After execution, verify the files were created/modified correctly:
ls -la
cat output.txt
Best Practices
Use Absolute or Relative Paths Explicitly: Always specify file paths clearly;
os.getcwd()helps confirm your working directory.Handle Errors Gracefully: Add try/except blocks to catch file I/O errors:
try: with open('file.txt', 'r') as f: content = f.read() except FileNotFoundError: print('File not found')Use Here-Docs for Complex Scripts: For scripts longer than a few lines, use bash here-documents to avoid escaping issues.
Clean Up Temporary Files: If you create temporary scripts, consider removing them after execution.
Check Working Directory First: Print
os.getcwd()to confirm you're operating in the expected directory.
Common Use Cases
- Reading configuration files from the workspace
- Writing generated reports or outputs
- Transforming data files (CSV, JSON, XML)
- Batch processing multiple files
- Generating structured documents (PDFs, spreadsheets)
Example: Processing Multiple Files
python3 -c "
import os
import glob
work_dir = os.getcwd()
files = glob.glob('*.txt')
for f in files:
with open(f, 'r') as file:
content = file.read()
# Process each file
with open(f'processed_{f}', 'w') as out:
out.write(content.strip().upper())
print(f'Processed {len(files)} files')
"
Troubleshooting
| Issue | Solution |
|---|---|
| File not found | Check os.getcwd() output; use absolute paths if needed |
| Permission denied | Ensure the directory is writable; avoid protected system paths |
| Encoding errors | Specify encoding explicitly: open('file.txt', 'r', encoding='utf-8') |
| Multi-line script issues | Use here-doc (<< 'EOF') instead of -c for complex scripts |
FAQ
Why does the agent print the working directory?
It shows which folder the script is using, so you can confirm the files are where you expect.
What about longer jobs?
The skill suggests writing a temporary Python script file first, then running it, for complex logic.
Does it delete the original file?
The example reads the input and writes a separate output file, so the input is left as it was.
Details
Original description by the author
Use run_shell with inline Python for reliable file I/O when execute_code_sandbox cannot access working directory files
repo: HKUDS/AgentPilot
Popularity
- GitHub stars
- 7.8k
- Ranking position
- #12980
- 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.