Pular para o conteúdo
Skillpedia
Código em geral7,8 mil · #13002

shell-python-heredoc

O que ela faz

Esta skill mostra ao agente de IA como executar um script Python de várias linhas pelo shell quando o sandbox continua falhando. É para pessoas cujos scripts precisam de várias importações ou de uma saída de erro clara.

Quando usar

  • ✓Quando o sandbox de código falhou duas ou mais vezes com erros não explicados.
  • ✓Quando um script tem várias importações, como reportlab ou pandas, e é longo demais para uma linha só.
  • ✓Quando você precisa ver a saída padrão e a saída de erro para entender o que deu errado.

Link da skill

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

Copie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.

Como usar

O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.

Mensagem pronta para colar

Use esta skill para me ajudar: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/shell-python-heredoc/SKILL.md Leia o arquivo SKILL.md desse link e siga as instruções dele na minha tarefa.
Quer que a sua IA encontre skills como esta sozinha?Instale o MCP grátis do Skillpedia: uma linha, e ela pesquisa entre 15.000+ skills antes de cada tarefa.Instalar em 1 minuto →

Exemplo do que pedir para a IA

“Execute meu script ReportLab de várias linhas pelo shell, porque o sandbox falhou duas vezes. Me mostre a saída.”

5 skills novas por semana. 1 minuto de leitura.

Como funciona

O agente envolve o script em um heredoc com um marcador de fim entre aspas e o executa com python3 e um limite de tempo. Depois lê a saída padrão e a saída de erro para ver se o trabalho funcionou.

Conteúdo técnico (SKILL.md original)

Texto original do autor, em inglês, direto do 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
Perguntas frequentes

Por que o marcador de fim precisa começar no início da linha?

O shell só reconhece o marcador de fim quando ele não tem espaços à frente.

Por que usar um marcador entre aspas?

Um marcador entre aspas impede o shell de alterar variáveis ou símbolos dentro do código Python.

O script mantém estado entre execuções?

A skill diz que essa abordagem serve para trabalhos que não precisam manter estado entre chamadas.

Detalhes

Descrição original do autor

Execute complex Python code via run_shell heredoc when execute_code_sandbox fails

repo: HKUDS/AgentPilot

Popularidade

Estrelas no GitHub
7,8 mil
Posição no ranking
#13002
Licença
MIT
Atualizada em
01/11/2026

Essa skill é útil?

0

Entre para votar.

Comentários

  • …

Mais skills deste repositório

Skills parecidas