Skip to content
cccskills
FreePublished on GitHub

run-shell-python-file-io

Read, write, and transform workspace files by running Python through run_shell when execute_code_sandbox cannot access them. The workflow covers explicit file paths, batch processing, error handling, and checking generated outputs.

OriginalShow the original description

Use run_shell with inline Python for reliable file I/O when execute_code_sandbox cannot access working directory files

See how to install

Good for

  • Reading configuration files in the workspace
  • Transforming CSV or JSON data files
  • Processing multiple text files in a batch
  • Saving generated reports to files

Files included (2)

  • SKILL.md3.6 KB
  • .skill_id38 B

SKILL.md (original)

Review the instructions the agent will receive before you install.

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

  1. Use Absolute or Relative Paths Explicitly: Always specify file paths clearly; os.getcwd() helps confirm your working directory.

  2. 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')
    
  3. Use Here-Docs for Complex Scripts: For scripts longer than a few lines, use bash here-documents to avoid escaping issues.

  4. Clean Up Temporary Files: If you create temporary scripts, consider removing them after execution.

  5. 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

IssueSolution
File not foundCheck os.getcwd() output; use absolute paths if needed
Permission deniedEnsure the directory is writable; avoid protected system paths
Encoding errorsSpecify encoding explicitly: open('file.txt', 'r', encoding='utf-8')
Multi-line script issuesUse here-doc (<< 'EOF') instead of -c for complex scripts

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Prepare audio stems, the separate parts of a track, for mixing by matching their durations with silence, loops, or crossfades. Verify each generated and processed file before moving to the next production step.

  • Match audio parts with different durations
  • Extend drums and melodic parts using suitable methods
  • Check audio specifications before mixing
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

Produce audio in separate stems, meaning individual instrument tracks, and verify each output as you go. Align track lengths with silence, loops, or crossfades, then apply effects, mix a master, and package the files.

  • Align instrument tracks to a reference audio file
  • Choose how to extend tracks that are too short
  • Verify audio properties after generation and effects
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

Build serverless endpoints that relay external API requests for a dashboard while keeping API keys on the server. Includes Vercel examples for input checks, caching, cross-origin access, and consistent JSON responses.

  • Connect a dashboard to external APIs without exposing API keys
  • Create endpoints for stock quotes and news
  • Standardize API responses and error handling
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

Produce a master track and separate audio parts through a structured Python workflow. Apply filters and reverb, export WAV files with consistent settings, package them in a ZIP archive, and check that the deliverables meet the requested specifications.

  • Export a master track with separate audio parts
  • Apply filters and reverb to audio
  • Check duration and format across deliverables
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

Keep document creation moving when web searches and page retrieval repeatedly fail. The skill preserves the original task, uses the model’s existing knowledge, and clearly identifies information that could not be checked against external sources.

  • Continue drafting after repeated web retrieval failures
  • Preserve task requirements during network errors
  • Mark information that could not be externally verified
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

When Python execution repeatedly fails in execute_code_sandbox, use a file-based alternative: save the script, run it through the shell, and capture results or errors. The guidance covers paths, imports, timeouts, structured output, and optional cleanup.

  • Retry Python work through the shell after repeated sandbox failures
  • Run longer tasks with an adjusted timeout
  • Execute Python work that needs multiple files or system utilities
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

See all skills by HKUDS

Report a problem with this skill