Aller au contenu
Skillpedia
Programmation générale7.8k · #12960

python-heredoc-fallback

Ce qu’il fait

Ce skill montre à l'agent IA comment exécuter du Python dans le shell avec un heredoc lorsque le bac à sable ne fonctionne pas. Il s'adresse aux personnes qui ont besoin de fichiers comme des graphiques, des documents Word ou des feuilles de calcul produits par Python.

Quand l’utiliser

  • ✓Quand le bac à sable de code échoue avec des erreurs de configuration ou de connexion.
  • ✓Quand j'ai besoin d'une image de graphique, d'un document Word ou d'une feuille de calcul créés par Python.
  • ✓Quand une tâche de génération de fichiers échoue sans cesse dans le bac à sable.

Lien du skill

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

Copiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.

Comment l’utiliser

Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.

Message prêt à coller

Utilise ce skill pour m’aider : https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-heredoc-fallback/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Fais un graphique en barres à partir de mon input.xlsx et enregistre-le en PNG. Le bac à sable échoue sans cesse.”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

L'agent installe d'abord les paquets nécessaires, puis lance le code Python dans le shell avec un heredoc. Le code crée le fichier et affiche un message à la fin.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis 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
Questions fréquentes

Quels types de fichiers peut-il créer ?

Le skill donne des exemples de graphiques, de documents Word et de feuilles de calcul produits avec des bibliothèques Python.

L'agent installe-t-il des paquets ?

Oui, le skill demande d'installer les paquets nécessaires avant l'exécution du bloc Python.

Pourquoi la ligne de fin EOF doit-elle commencer en début de ligne ?

Le shell ne reconnaît le marqueur de fin que lorsqu'il se trouve au début d'une ligne.

Détails

Description originale de l’auteur

Use shell Python heredoc as fallback when code sandbox fails

repo: HKUDS/AgentPilot

Popularité

Étoiles GitHub
7.8k
Position au classement
#12960
Licence
MIT
Mis à jour
01/11/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires