본문으로 건너뛰기
Skillpedia
일반 코딩7.8k · #12960

python-heredoc-fallback

하는 일

이 스킬은 샌드박스가 작동하지 않을 때 셸에서 heredoc으로 Python을 실행하는 방법을 보여 줍니다. Python으로 만든 차트, Word 문서, 스프레드시트 같은 파일이 필요한 사람에게 맞습니다.

사용하는 경우

  • ✓코드 샌드박스가 설정이나 연결 오류로 실패할 때.
  • ✓Python으로 만든 차트 이미지, Word 문서 또는 스프레드시트가 필요할 때.
  • ✓파일 생성 작업이 샌드박스에서 계속 실패하는 경우.

스킬 링크

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

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-heredoc-fallback/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“input.xlsx로 막대 차트를 만들어 PNG로 저장해 주세요. 샌드박스가 계속 실패합니다.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 먼저 필요한 패키지를 설치한 뒤, heredoc으로 셸에서 Python 코드를 실행합니다. 코드가 파일을 만들고 끝나면 메시지를 출력합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 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
자주 묻는 질문

어떤 종류의 파일을 만들 수 있나요?

스킬은 Python 라이브러리로 만든 차트, Word 문서, 스프레드시트 예시를 보여 줍니다.

에이전트가 패키지를 설치하나요?

네, 스킬은 Python 블록을 실행하기 전에 필요한 패키지를 설치하라고 말합니다.

EOF 끝 줄은 왜 왼쪽 끝에 있어야 하나요?

셸은 줄의 맨 앞에 있는 경우에만 끝 표시를 인식하기 때문입니다.

상세 정보

작성자의 원본 설명

Use shell Python heredoc as fallback when code sandbox fails

repo: HKUDS/AgentPilot

인기도

GitHub 스타
7.8k
순위
#12960
라이선스
MIT
업데이트
2026. 11. 1.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬