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가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
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
Use descriptive filenames: Name scripts according to their purpose (e.g.,
calculate_pnl.py,transform_data.py)Set appropriate timeouts: For data processing scripts, use longer timeouts (60-300 seconds)
Specify working directory: If the script depends on relative paths, include
cd /path && python3 script.pyHandle errors gracefully: Check shell output for errors and retry if needed
Clean up temporary files: Don't leave
.pyfiles 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.
댓글
- …
이 저장소의 다른 스킬
agentpilot
7.8k작업을 준비하고 AgentPilot 루프를 실행해 변경을 제안, 테스트, 점수화하면서 프로젝트를 단계적으로 개선하도록 돕습니다.
openspace
7.8k에이전트 스킬을 저장하고 가져오는 도구인 OpenSpace를 설정하고, MCP를 통해 AI 앱에 연결하도록 돕습니다.
rsi-arena
7.8kAIME나 Terminal-Bench 같은 표준 AI 벤치마크 테스트를 설정하고 실행해 서로 다른 개선 방법을 비교하도록 돕습니다.
experiment-guide
7.8k프로그램을 개선하는 방법을 조사하면서 작은 실험을 계획하고, 결과를 읽고, 발견 사항을 기록하도록 돕습니다.