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

reliable-script-execution

하는 일

이 스킬은 Python 코드를 실행하기 전에 파일로 저장하라고 AI 에이전트에게 말합니다. 인라인 Python 실행이 알 수 없는 오류로 계속 실패하는 사람에게 맞습니다.

사용하는 경우

  • ✓특히 여러 줄 스크립트에서 인라인 Python 코드가 알 수 없는 오류로 실패할 때.
  • ✓따옴표나 특수 문자가 많아서 인라인 실행이 깨지는 코드일 때.
  • ✓실행한 스크립트의 기록을 남기고 싶은 경우.

스킬 링크

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

AI에게 요청하는 예시

“제 지출을 JSON 보고서로 만드는 짧은 Python 스크립트를 작성해서 저장한 뒤 실행해 주세요.”

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

작동 방식

에이전트는 명확한 폴더에 코드를 .py 파일로 쓰고, 시간 제한을 둔 셸 명령으로 실행합니다. 작업이 끝나면 임시 파일을 지울 수 있습니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Reliable Script Execution

When executing Python code via shell commands, avoid inline heredoc execution which can fail unpredictably with 'unknown error'. Use this two-step file-first approach for more reliable script execution.

Problem

Direct heredoc Python execution like:

python3 << 'EOF'
# complex code here
EOF

Can fail with 'unknown error', especially when:

  • Script contains multiple lines or complex logic
  • Special characters or quotes are present
  • Working directory context matters

Solution: File-First Approach

Step 1: Write Python Script to File

Use write_file to save your Python code to a .py file:

write_file(path="./temp_script.py", content="""
import json

data = {"key": "value"}
print(json.dumps(data))
""")

Step 2: Execute via Shell

Use run_shell with explicit working directory:

run_shell(command="python3 ./temp_script.py", timeout=60)

Step 3: Clean Up (Optional)

Remove temporary files after execution:

run_shell(command="rm ./temp_script.py")

Complete Example

Task: Generate a JSON report with calculations

# Step 1: Write the script
write_file(
    path="./generate_report.py",
    content="""
import json
from datetime import datetime

revenue = 500000.00
expenses = 379577.06
net_income = revenue - expenses

report = {
    "generated": datetime.now().isoformat(),
    "revenue": revenue,
    "expenses": expenses,
    "net_income": net_income
}

print(json.dumps(report, indent=2))
"""
)

# Step 2: Execute
run_shell(command="python3 ./generate_report.py", timeout=60)

# Step 3: Clean up
run_shell(command="rm ./generate_report.py")

Best Practices

  1. Use descriptive filenames: Name scripts according to their purpose (e.g., calculate_pnl.py, transform_data.py)

  2. Set appropriate timeouts: For data processing scripts, use longer timeouts (60-300 seconds)

  3. Specify working directory: If the script depends on relative paths, include cd /path && python3 script.py

  4. Handle errors gracefully: Check shell output for errors and retry if needed

  5. Clean up temporary files: Don't leave .py files cluttering the workspace unless they need to persist

When to Use This Pattern

  • Executing multi-line Python code via shell
  • Scripts with complex string handling or special characters
  • When heredoc execution has failed previously
  • Any scenario where reliability matters more than brevity

Anti-Pattern to Avoid

Do NOT rely on heredoc for production-critical scripts:

# Unreliable - may fail with 'unknown error'
python3 << 'EOF'
# Your code here
EOF

Use file-first approach instead for consistent, debuggable execution.

자주 묻는 질문

파일이 인라인 코드보다 믿을 만한 이유는 무엇인가요?

스킬은 인라인 heredoc 실행이 예측할 수 없이 실패할 수 있는 반면, 저장된 파일은 더 분명한 결과를 준다고 말합니다.

작업 후 파일을 지워야 하나요?

스킬은 정리가 선택 사항이라고 말하므로, 기록을 원하면 파일을 남길 수 있습니다.

시간 제한을 둘 수 있나요?

네, 스킬의 예제는 셸 명령에 시간 제한을 전달합니다.

상세 정보

작성자의 원본 설명

Execute Python scripts reliably using file-first approach instead of heredoc

repo: HKUDS/AgentPilot

인기도

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

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬