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

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가 스킬을 읽고 지침을 따릅니다.

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

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

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_sandbox has 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

  1. Use << 'EOF' (with single quotes) to prevent shell variable expansion
  2. Indent Python code relative to the heredoc delimiter
  3. End with EOF on its own line (no leading whitespace)
  4. 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_sandbox for simpler scripts when available
  • Use shell_agent for tasks requiring autonomous iteration and error recovery
  • Consider writing scripts to .py files 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.

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬