Saltar al contenido
Skillpedia
Programación general7,8 mil · #12980

run-shell-python-file-io

Qué hace

Esta skill muestra al agente de IA cómo leer, modificar y escribir archivos con Python ejecutado en la shell. Está pensada para quienes su entorno aislado no puede ver los archivos de su carpeta de trabajo.

Cuándo usarla

  • ✓Cuando el entorno aislado de código no puede acceder a los archivos de tu carpeta de trabajo.
  • ✓Cuando necesitas leer un archivo, cambiar su texto y guardar el resultado.
  • ✓Cuando un trabajo largo con archivos necesita un script temporal de Python para ejecutar más pasos.

Link de la skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/run-shell-python-file-io/SKILL.md

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/run-shell-python-file-io/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“Lee input.txt de mi carpeta de trabajo, pasa el texto a mayúsculas y guárdalo como output.txt. El entorno aislado no puede ver la carpeta.”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

El agente ejecuta en la shell un programa corto de Python que lee el archivo de entrada, procesa su texto y escribe el archivo de salida. Imprime la carpeta de trabajo y un mensaje de finalización para que puedas confirmar el resultado.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de 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

  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

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
Preguntas frecuentes

¿Por qué el agente imprime la carpeta de trabajo?

Muestra qué carpeta usa el script, así puedes confirmar que los archivos están donde esperas.

¿Y en los trabajos más largos?

La skill sugiere escribir primero un archivo de script temporal de Python y ejecutarlo, si la lógica es compleja.

¿Borra el archivo original?

El ejemplo lee la entrada y escribe un archivo de salida aparte, así que la entrada queda como estaba.

Detalles

Descripción original del autor

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

repo: HKUDS/AgentPilot

Popularidad

Estrellas en GitHub
7,8 mil
Posición en el ranking
#12980
Licencia
MIT
Actualizada
1/11/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas