shell-python-heredoc
하는 일
이 스킬은 샌드박스가 계속 실패할 때 AI 에이전트가 여러 줄로 된 Python 스크립트를 셸로 실행하는 방법을 보여 줍니다. 여러 import가 필요하거나 명확한 오류 출력이 필요한 스크립트를 위한 스킬입니다.
사용하는 경우
- ✓코드 샌드박스가 설명되지 않는 오류로 두 번 이상 실패했을 때.
- ✓스크립트에 reportlab이나 pandas 같은 import가 여럿 있고 한 줄로 쓰기에는 너무 길 때.
- ✓무엇이 잘못되었는지 보려고 표준 출력과 표준 오류를 확인해야 할 때.
스킬 링크
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/shell-python-heredoc/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“샌드박스가 두 번 실패했으니 여러 줄로 된 제 ReportLab 스크립트를 셸로 실행해 주세요. 출력도 보여 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
에이전트는 따옴표가 있는 종료 표시로 스크립트를 heredoc에 감싸고, 시간 제한을 두고 python3로 실행합니다. 그다음 표준 출력과 표준 오류를 읽어 작업이 성공했는지 확인합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 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_sandboxhas 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
- Use
<< 'EOF'(with single quotes) to prevent shell variable expansion - Indent Python code relative to the heredoc delimiter
- End with
EOFon its own line (no leading whitespace) - 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_sandboxfor simpler scripts when available - Use
shell_agentfor tasks requiring autonomous iteration and error recovery - Consider writing scripts to
.pyfiles for complex, reusable code
자주 묻는 질문
종료 표시는 왜 줄의 맨 앞에 있어야 하나요?
셸은 앞에 공백이 없는 종료 표시만 인식하기 때문입니다.
왜 따옴표가 있는 표시를 쓰나요?
따옴표가 있으면 셸이 Python 코드 안의 변수나 기호를 바꾸지 않습니다.
스크립트가 실행 사이에 상태를 유지하나요?
스킬은 이 방식이 호출 사이에 상태를 유지할 필요가 없는 작업을 위한 것이라고 설명합니다.
상세 정보
작성자의 원본 설명
Execute complex Python code via run_shell heredoc when execute_code_sandbox fails
repo: HKUDS/AgentPilot
인기도
- GitHub 스타
- 7.8k
- 순위
- #13002
- 라이선스
- MIT
- 업데이트
- 2026. 11. 1.
댓글
- …
이 저장소의 다른 스킬
agentpilot
7.8k작업을 준비하고 AgentPilot 루프를 실행해 변경을 제안, 테스트, 점수화하면서 프로젝트를 단계적으로 개선하도록 돕습니다.
openspace
7.8k에이전트 스킬을 저장하고 가져오는 도구인 OpenSpace를 설정하고, MCP를 통해 AI 앱에 연결하도록 돕습니다.
rsi-arena
7.8kAIME나 Terminal-Bench 같은 표준 AI 벤치마크 테스트를 설정하고 실행해 서로 다른 개선 방법을 비교하도록 돕습니다.
experiment-guide
7.8k프로그램을 개선하는 방법을 조사하면서 작은 실험을 계획하고, 결과를 읽고, 발견 사항을 기록하도록 돕습니다.