excel-heredoc-fallback
하는 일
이 스킬은 코드 샌드박스가 실패할 때 수식, 서식, 병합 셀이 있는 Excel 스프레드시트를 만드는 예비 방법입니다. 완성도 높은 스프레드시트가 필요한 사람에게 맞습니다.
사용하는 경우
- ✓샌드박스에서 openpyxl 가져오기 오류나 권한 문제가 생길 때.
- ✓파일에 Excel 서식, 색, 병합 셀 또는 수식이 필요할 때.
- ✓같은 스프레드시트 작업에서 샌드박스가 여러 번 실패한 경우.
스킬 링크
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/excel-heredoc-fallback/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“색이 있는 제목과 수식 합계가 들어간 Excel 파일을 만들어 주세요. 샌드박스가 계속 실패하니 다른 방법으로 실행해 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
AI는 먼저 샌드박스를 시도하고, 실패를 감지하면 heredoc을 사용해 셸 명령으로 openpyxl 코드를 실행합니다. 이렇게 하면 파일이 디스크에 저장됩니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
Excel Creation via Shell Heredoc Fallback
Overview
When creating Excel files with openpyxl, execute_code_sandbox may fail due to sandbox restrictions, missing dependencies, or permission issues. This skill provides a reliable fallback: execute Python code via run_shell using an inline heredoc script. This approach often succeeds where the sandbox fails and supports full openpyxl features including styling, formulas, and formatting.
When to Use This Skill
execute_code_sandboxfails when importing or using openpyxl- Sandbox shows errors about missing packages, permissions, or execution restrictions
- You need to create Excel files with advanced formatting (styles, colors, merged cells, formulas)
- Previous sandbox attempts have failed multiple times
Step-by-Step Instructions
Step 1: Attempt Sandbox Execution First
Always try execute_code_sandbox first, as it's cleaner and preferred when it works:
from openpyxl import Workbook
from openpyxl.styles import Font, Fill, PatternFill, Alignment
wb = Workbook()
ws = wb.active
ws['A1'] = 'Header'
ws['A1'].font = Font(bold=True)
wb.save('output.xlsx')
Step 2: Detect Sandbox Failure
Watch for these failure indicators:
- ImportError for openpyxl or related modules
- Permission denied errors
- File write failures
- Repeated retry loops without success
- Timeout or resource errors
Step 3: Fall Back to Shell Heredoc
When sandbox fails, switch to run_shell with a Python heredoc:
python3 << 'EOF'
from openpyxl import Workbook
from openpyxl.styles import Font, Fill, PatternFill, Alignment, Border, Side
# Create workbook
wb = Workbook()
ws = wb.active
ws.title = "Sheet1"
# Add data with formatting
ws['A1'] = 'Name'
ws['B1'] = 'Value'
ws['A1'].font = Font(bold=True, size=14)
ws['B1'].font = Font(bold=True, size=14)
# Add rows
data = [
['Item 1', 100],
['Item 2', 200],
['Item 3', 150],
]
for row_idx, row_data in enumerate(data, start=2):
for col_idx, value in enumerate(row_data, start=1):
cell = ws.cell(row=row_idx, column=col_idx, value=value)
cell.alignment = Alignment(horizontal='center')
# Add formulas if needed
ws['B5'] = '=SUM(B2:B4)'
# Save the file
wb.save('output.xlsx')
print("Excel file created successfully: output.xlsx")
EOF
Step 4: Use run_shell Tool
Execute the heredoc via run_shell:
tool: run_shell
command: python3 << 'EOF'
[from openpyxl code here]
EOF
Step 5: Verify File Creation
After execution, confirm the file was created:
tool: run_shell
command: ls -lh output.xlsx
Check the file size to ensure it's not empty (should be >1KB for typical spreadsheets).
Best Practices
1. Use Single-Quoted Heredoc Delimiter
Always use << 'EOF' (with quotes) to prevent shell variable expansion inside the Python code.
2. Include Error Handling
Add try/except blocks to catch and report issues:
try:
from openpyxl import Workbook
# ... your code ...
wb.save('output.xlsx')
print("SUCCESS: File created")
except Exception as e:
print(f"ERROR: {e}")
exit(1)
3. Print Confirmation Messages
Always include print statements that confirm success or report specific errors. This helps debug issues.
4. Use Absolute or Explicit Paths
When saving files, use explicit paths to avoid confusion:
wb.save('./output.xlsx') # Explicit current directory
# or
wb.save('/workspace/output.xlsx') # Absolute path
5. Keep Scripts Concise
Heredoc scripts should be focused and not excessively long. If the Excel logic is complex, consider writing a separate .py file first using write_file, then executing it.
Advanced Formatting Examples
Cell Styling
from openpyxl.styles import Font, PatternFill, Alignment, Border, Side
# Define styles
bold_font = Font(bold=True, size=12)
header_fill = PatternFill(start_color='4472C4', end_color='4472C4', fill_type='solid')
center_align = Alignment(horizontal='center', vertical='center')
thin_border = Border(
left=Side(style='thin'),
right=Side(style='thin'),
top=Side(style='thin'),
bottom=Side(style='thin')
)
# Apply to cells
ws['A1'].font = bold_font
ws['A1'].fill = header_fill
ws['A1'].alignment = center_align
Column Width and Row Height
ws.column_dimensions['A'].width = 20
ws.column_dimensions['B'].width = 15
ws.row_dimensions[1].height = 25
Merged Cells
ws.merge_cells('A1:C1'
자주 묻는 질문
heredoc은 무엇인가요?
여러 줄의 코드를 한 번에 셸 명령에 전달하는 방법입니다.
어떤 실패가 전환을 일으키나요?
가이드는 가져오기 오류, 권한 거부, 쓰기 실패, 반복 재시도와 시간 초과를 꼽습니다.
수식을 추가할 수 있나요?
네, 가이드는 수식과 스타일 같은 openpyxl의 전체 기능을 지원한다고 설명합니다.
상세 정보
작성자의 원본 설명
Create Excel files with openpyxl by falling back to shell-based Python heredoc when sandbox execution fails
repo: HKUDS/AgentPilot
인기도
- GitHub 스타
- 7.8k
- 순위
- #12874
- 라이선스
- 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프로그램을 개선하는 방법을 조사하면서 작은 실험을 계획하고, 결과를 읽고, 발견 사항을 기록하도록 돕습니다.
비슷한 스킬
feishu-doc
394k에이전트가 문서 도구를 사용해 텍스트, 이미지, 표를 포함한 Feishu 클라우드 문서를 읽고, 만들고, 편집하도록 돕습니다.
feishu-drive
394k에이전트가 봇과 공유된 Feishu 클라우드 폴더의 파일을 찾아보고, 정리하고, 댓글을 달도록 돕습니다.
feishu-perm
394k에이전트가 요청을 충족하는 가장 작은 권한을 골라, Feishu 파일에 누가 접근할 수 있는지 확인하고 바꾸도록 돕습니다.