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

python-heredoc-fallback

O que ela faz

Esta skill mostra ao agente de IA como executar Python no shell com um heredoc quando o sandbox não está funcionando. É para pessoas que precisam de arquivos como gráficos, documentos Word ou planilhas gerados com Python.

Quando usar

  • ✓Quando o sandbox de código falha com erros de configuração ou de conexão.
  • ✓Quando você precisa de uma imagem de gráfico, de um documento Word ou de uma planilha criados com Python.
  • ✓Quando uma tarefa de geração de arquivos continua falhando no sandbox.

Link da skill

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

“Crie um gráfico de barras a partir do meu input.xlsx e salve como PNG. O sandbox continua falhando.”

5 skills novas por semana. 1 minuto de leitura.

Como funciona

O agente instala antes os pacotes necessários e depois executa o código Python no shell com um heredoc. O código cria o arquivo e imprime uma mensagem quando termina.

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

Texto original do autor, em inglês, direto do GitHub.

Python Heredoc Fallback for Code Execution

When to Use

Use this pattern when execute_code_sandbox fails with e2b initialization errors, sandbox connection issues, or other execution environment problems. This is especially reliable for file generation tasks.

Core Pattern

Instead of execute_code_sandbox, run Python code directly in the shell using a heredoc:

python3 << 'EOF'
# Your Python code here
import sys
print("Python code executing in shell")
EOF

Key Syntax Rules

  1. Use single-quoted EOF (<< 'EOF') to prevent shell variable expansion within the Python code
  2. No indentation before EOF - the closing delimiter must be at the start of the line
  3. Install packages first if needed, before the Python heredoc block

Common Use Cases

1. Matplotlib Graph Generation

python3 << 'EOF'
import matplotlib.pyplot as plt
import pandas as pd

# Load data
data = pd.read_excel('input.xlsx')

# Create visualization
plt.figure(figsize=(10, 6))
plt.plot(data['x'], data['y'])
plt.xlabel('X Label')
plt.ylabel('Y Label')
plt.title('Graph Title')
plt.savefig('output_graph.png', dpi=300, bbox_inches='tight')
plt.close()

print("Graph saved successfully")
EOF

2. Python-docx Document Creation

pip install python-docx -q

python3 << 'EOF'
from docx import Document
from docx.shared import Inches, Pt
from docx.enum.text import WD_ALIGN_PARAGRAPH

doc = Document()

# Add title
title = doc.add_heading('Document Title', 0)
title.alignment = WD_ALIGN_PARAGRAPH.CENTER

# Add sections
doc.add_heading('Section 1', level=1)
doc.add_paragraph('Content for section 1.')

# Add table
table = doc.add_table(rows=3, cols=3)
table.style = 'Table Grid'

# Save document
doc.save('output.docx')
print("Document created successfully")
EOF

3. General File Operations

python3 << 'EOF'
import json
import os

# Read input file
with open('input.json', 'r') as f:
    data = json.load(f)

# Process data
result = {'processed': True, 'items': len(data)}

# Write output
with open('output.json', 'w') as f:
    json.dump(result, f, indent=2)

print(f"Processed {result['items']} items")
EOF

Best Practices

  1. Install dependencies first: Run pip install package-name -q before the Python block if packages aren't guaranteed to be available
  2. Verify file paths: Files are read from and written to the current working directory
  3. Add print statements: Include progress/output messages to verify execution succeeded
  4. Close resources: Explicitly close matplotlib figures and file handles
  5. Handle errors gracefully: Add try/except blocks for production code

Troubleshooting

Issue Solution
Module not found Add pip install <module> -q before Python block
File not found Verify file exists in current directory with ls
Permission denied Check file permissions and directory write access
Syntax errors Ensure proper Python indentation within heredoc

Advantages Over execute_code_sandbox

  • No initialization overhead - runs immediately in existing shell
  • Persistent environment - maintains state across multiple commands
  • Direct file system access - no sandbox isolation issues
  • Full system Python - access to all installed packages
  • Reliable for large files - no sandbox size restrictions
Perguntas frequentes

Que tipos de arquivo ele pode criar?

A skill traz exemplos de gráficos, documentos Word e planilhas feitos com bibliotecas Python.

O agente instala pacotes?

Sim. A skill diz para instalar os pacotes necessários antes de o bloco Python ser executado.

Por que a linha EOF de fechamento precisa começar na margem esquerda?

O shell só reconhece o marcador de fim quando ele fica no início de uma linha.

Detalhes

Descrição original do autor

Use shell Python heredoc as fallback when code sandbox fails

repo: HKUDS/AgentPilot

Popularidade

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

Essa skill é útil?

0

Entre para votar.

Comentários

  • …

Mais skills deste repositório

Skills parecidas