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

shell-python-heredoc

Qué hace

Esta skill muestra al agente de IA cómo ejecutar un script de Python de varias líneas a través de la shell cuando el entorno aislado sigue fallando. Está pensada para quienes sus scripts necesitan varias importaciones o una salida de error clara.

Cuándo usarla

  • ✓Cuando el entorno aislado de código ha fallado dos veces o más con errores sin explicación.
  • ✓Cuando un script tiene varias importaciones, como reportlab o pandas, y es demasiado largo para una sola línea.
  • ✓Cuando necesitas ver stdout y stderr para entender qué salió mal.

Link de la skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/shell-python-heredoc/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/shell-python-heredoc/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

“Ejecuta mi script de ReportLab de varias líneas a través de la shell, porque el entorno aislado falló dos veces. Muéstrame la salida.”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

El agente envuelve el script en un heredoc con un marcador de fin entre comillas y lo ejecuta con python3 y un límite de tiempo. Después lee stdout y stderr para ver si el trabajo salió bien.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de GitHub.

Shell Python Heredoc (Fallback Pattern)

Overview

When execute_code_sandbox fails repeatedly (e.g., with "unknown error"), use run_shell with a Python heredoc as a reliable fallback for executing multi-line Python scripts with imports.

When to Use

  • execute_code_sandbox has failed 2+ times with unexplained errors
  • You need to run Python code with multiple imports (e.g., ReportLab, pandas)
  • The script is too complex for a one-liner but doesn't require persistence between calls
  • You need better error visibility from raw stdout/stderr

How to Use

Basic Pattern

run_shell(
    command="""python3 << 'EOF'
import sys
# Your Python code here
print("Hello from heredoc")
EOF""",
    timeout=300
)

Key Syntax Rules

  1. Use << 'EOF' (with single quotes) to prevent shell variable expansion
  2. Indent Python code relative to the heredoc delimiter
  3. End with EOF on its own line (no leading whitespace)
  4. Capture output from stdout/stderr for debugging

Example: Generating a PDF with ReportLab

run_shell(
    command="""python3 << 'EOF'
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

c = canvas.Canvas("output.pdf", pagesize=letter)
c.drawString(100, 750, "Hello PDF")
c.save()
print("PDF created successfully")
EOF""",
    timeout=300
)

Example: Multi-file Data Processing

run_shell(
    command="""python3 << 'EOF'
import pandas as pd
import json

# Load and process data
df = pd.read_csv("data.csv")
summary = df.describe()

# Output results
print(summary.to_string())
with open("summary.json", "w") as f:
    json.dump(summary.to_dict(), f)
print("Processing complete")
EOF""",
    timeout=300
)

Advantages Over execute_code_sandbox

  • More reliable for complex imports (no sandbox isolation issues)
  • Full stdout/stderr access for debugging
  • Longer timeout flexibility (60s default vs 30s)
  • Direct filesystem access without ARTIFACT_PATH indirection

Disadvantages

  • No persistent state between calls (each heredoc is a fresh process)
  • Verbose for simple one-liners
  • Shell escaping may be needed for complex string literals

Troubleshooting

Issue Solution
EOF not recognized Ensure EOF is on its own line with no leading spaces
Import errors Verify packages are installed in the shell environment
File not found Use absolute paths or check working directory with pwd
Syntax errors Check Python indentation within heredoc

See Also

  • Use execute_code_sandbox for simpler scripts when available
  • Use shell_agent for tasks requiring autonomous iteration and error recovery
  • Consider writing scripts to .py files for complex, reusable code
Preguntas frecuentes

¿Por qué el marcador de fin debe estar al principio de una línea?

La shell solo reconoce el marcador de fin cuando no tiene espacios al principio.

¿Por qué usar un marcador entre comillas?

Un marcador entre comillas impide que la shell cambie las variables o los símbolos dentro del código de Python.

¿Mantiene el script el estado entre ejecuciones?

La skill indica que este enfoque es para trabajos que no necesitan conservar el estado entre llamadas.

Detalles

Descripción original del autor

Execute complex Python code via run_shell heredoc when execute_code_sandbox fails

repo: HKUDS/AgentPilot

Popularidad

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

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas