| name | run-shell-python-file-io |
| description | Use run_shell with inline Python for reliable file I/O when execute_code_sandbox cannot access working directory files |
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()
with open('data.json', 'r') as f:
data = json.load(f)
result = {k: v * 2 k, v data.items()}
with open(, ) as f:
json.dump(result, f, indent=2)
(f)
EOF
python3 /tmp/process.py