Zum Inhalt springen
Skillpedia
Allgemeines Programmieren7.8k · #12960

python-heredoc-fallback

Was er macht

Dieser Skill zeigt dem KI-Agenten, wie er Python per Heredoc in der Shell ausführt, wenn die Sandbox nicht funktioniert. Er richtet sich an Menschen, die Dateien wie Diagramme, Word-Dokumente oder Tabellen mit Python erstellen lassen.

Wann du ihn nutzt

  • ✓Wenn die Code-Sandbox mit Einrichtungs- oder Verbindungsfehlern scheitert.
  • ✓Wenn du ein Diagramm als Bild, ein Word-Dokument oder eine Tabelle brauchst, die mit Python erstellt wird.
  • ✓Wenn eine Datei-Erstellung in der Sandbox immer wieder scheitert.

Link zum Skill

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

Kopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.

So nutzt du ihn

Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.

Fertige Nachricht zum Einfügen

Nutze diesen Skill, um mir zu helfen: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-heredoc-fallback/SKILL.md Lies die SKILL.md unter diesem Link und folge ihren Anweisungen für meine Aufgabe.
Soll deine KI Skills wie diesen selbst finden?Installiere den kostenlosen Skillpedia-MCP: eine Zeile, und sie durchsucht vor jeder Aufgabe 15.000+ Skills.In 1 Minute installieren →

Beispielanfrage an deine KI

“Erstelle aus meiner input.xlsx ein Balkendiagramm und speichere es als PNG. Die Sandbox scheitert immer wieder, also führe es in der Shell aus.”

5 neue Skills pro Woche. 1 Minute Lesezeit.

So funktioniert es

Der Agent installiert zuerst benötigte Pakete und führt dann den Python-Code in der Shell mit einem Heredoc aus. Der Code erzeugt die Datei und gibt eine Meldung aus, wenn er fertig ist.

Technischer Inhalt (originale SKILL.md)

Originaltext des Autors, auf Englisch, direkt von 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
Häufige Fragen

Welche Arten von Dateien kann er erstellen?

Der Skill nennt Beispiele für Diagramme, Word-Dokumente und Tabellen, die mit Python-Bibliotheken erzeugt werden.

Installiert der Agent Pakete?

Ja. Der Skill sagt, benötigte Pakete vor dem Python-Block zu installieren.

Warum muss das EOF-Endzeichen am linken Rand stehen?

Die Shell erkennt das Endzeichen nur, wenn es am Zeilenanfang steht.

Details

Originalbeschreibung des Autors

Use shell Python heredoc as fallback when code sandbox fails

repo: HKUDS/AgentPilot

Beliebtheit

GitHub-Sterne
7.8k
Platz im Ranking
#12960
Lizenz
MIT
Aktualisiert
1.11.2026

Ist dieser Skill nützlich?

0

Anmelden um abzustimmen.

Kommentare

  • …

Weitere Skills aus diesem Repository

Ähnliche Skills