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

python-shell-workaround

하는 일

이 스킬은 openpyxl, python-docx, pandas 같은 패키지를 쓰는 Python 코드의 우회 방법입니다. 샌드박스에 그 패키지가 없는 사람에게 맞습니다.

사용하는 경우

  • ✓샌드박스에서 openpyxl이나 pandas 같은 패키지를 가져오는 코드가 실패할 때.
  • ✓패키지를 테스트하려고 한 줄짜리 빠른 Python 명령이 필요할 때.
  • ✓샌드박스 대신 셸에서 긴 Python 작업을 실행해야 하는 경우.

스킬 링크

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

AI에게 요청하는 예시

“openpyxl로 헤더 행이 있는 Excel 파일을 만들어 주세요. 샌드박스가 실패했으니 다른 방법으로 실행해 주세요.”

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

작동 방식

에이전트는 Python 코드를 한 줄 셸 명령이나 heredoc으로 바꾸고, 셸 도구로 실행합니다. 그다음 출력을 확인해 파일이 만들어졌는지 확인합니다.

기술 내용 (원본 SKILL.md)

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

Python Shell Workaround

When to Use This Skill

Use this pattern when execute_code_sandbox fails with Python code that requires external packages (like openpyxl, python-docx, pandas, etc.) that may not be available in the sandbox environment.

The Pattern

Instead of relying solely on execute_code_sandbox, use run_shell with inline Python commands as a fallback:

python3 -c "your python code here"

Step-by-Step Instructions

Step 1: Detect Sandbox Failure

Watch for errors like:

  • ModuleNotFoundError for common packages
  • Import errors for external libraries
  • Sandbox environment limitations

Step 2: Convert Python Code to Shell Command

Transform your Python script into a one-liner or use a heredoc for longer scripts:

For simple code:

python3 -c "import openpyxl; wb = openpyxl.Workbook(); wb.save('file.xlsx')"

For complex code (using heredoc):

python3 << 'EOF'
import openpyxl
from openpyxl.utils import get_column_letter

wb = openpyxl.Workbook()
ws = wb.active
ws['A1'] = 'Header'
wb.save('output.xlsx')
print('File created successfully')
EOF

Step 3: Execute with run_shell

Use run_shell to execute the command:

tool: run_shell
command: python3 -c "import openpyxl; print('Package available')"

Step 4: Verify Output

Check the stdout/stderr from run_shell to confirm success, then proceed with subsequent steps.

Best Practices

  1. Escape quotes properly: Use single quotes inside double-quoted strings or vice versa
  2. Use heredocs for multiline code: Cleaner and easier to debug
  3. Install packages if needed: Add pip install package before your Python command if packages are missing
  4. Chain commands safely: Use && to ensure prerequisites succeed before running Python code

Example Scenarios

Creating Excel Files

python3 << 'EOF'
import openpyxl
from openpyxl.worksheet.datavalidation import DataValidation

wb = openpyxl.Workbook()
ws = wb.active
ws.title = "Data"

# Add headers
headers = ['Name', 'Email', 'Status']
for col, header in enumerate(headers, 1):
    ws.cell(row=1, column=col, value=header)

wb.save('output.xlsx')
EOF

Creating Word Documents

python3 -c "
from docx import Document
doc = Document()
doc.add_heading('Report', 0)
doc.save('report.docx')
print('Document created')
"

Limitations

  • Complex multiline scripts are harder to maintain as one-liners
  • Debugging is less convenient than in sandbox
  • Some packages may still not be available in the shell environment

Related Patterns

  • If packages are truly unavailable, consider installing them first: pip install package_name && python3 -c "..."
  • For persistent scripts, write to a .py file first, then execute with python3 script.py
자주 묻는 질문

한 줄 명령과 heredoc은 언제 각각 쓰나요?

짧은 코드에는 한 줄 명령이, 여러 단계가 있는 긴 스크립트에는 heredoc이 맞습니다.

에이전트는 어떻게 작동했다는 것을 아나요?

출력된 결과를 확인한 뒤 파일이 있는지 확인합니다.

스킬은 어떤 패키지를 언급하나요?

샌드박스에 없을 수 있는 패키지의 예로 openpyxl, python-docx, pandas를 언급합니다.

상세 정보

작성자의 원본 설명

Workaround for executing Python code with external packages when sandbox fails

repo: HKUDS/AgentPilot

인기도

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

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬