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

python-shell-fallback

하는 일

이 스킬은 샌드박스에 패키지가 없을 때 라이브러리 기반 Python 작업을 셸로 옮기도록 돕습니다. PDF나 차트처럼 라이브러리가 많이 필요한 결과물을 원하는 사람에게 맞습니다.

사용하는 경우

  • ✓샌드박스가 ModuleNotFoundError나 비슷한 가져오기 오류를 낼 때.
  • ✓샌드박스에 필요한 라이브러리가 없어 PDF나 차트가 필요한 경우.
  • ✓샌드박스 실행이 패키지 문제로 계속 실패할 때.

스킬 링크

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

AI에게 요청하는 예시

“이 텍스트로 PDF 보고서를 만들어 주세요. 샌드박스가 모듈이 없다고 하니 셸에서 실행해 주세요.”

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

작동 방식

에이전트는 누락된 패키지 오류를 알아차리고, 코드를 heredoc을 이용해 셸에서 실행하도록 고칩니다. 셸 환경에는 보통 더 많은 설치된 패키지가 있습니다.

기술 내용 (원본 SKILL.md)

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

Python Shell Fallback

When execute_code_sandbox fails for Python code that depends on external libraries, use run_shell with a heredoc Python script as a reliable fallback. The shell environment typically has better access to installed packages and system configuration than the sandbox.

When to Use This Pattern

Apply this skill when:

  • execute_code_sandbox returns errors related to missing libraries (e.g., ModuleNotFoundError)
  • The code requires packages that may not be installed in the sandbox environment
  • You need PDF generation, data visualization, or other library-heavy operations
  • Previous sandbox execution attempts have failed with import errors

How to Implement

Step 1: Identify the Failure

Check if the sandbox error indicates a library/dependency issue:

  • ModuleNotFoundError: No module named 'xxx'
  • ImportError: cannot import name 'xxx'
  • Similar package-related errors

Step 2: Convert to Shell Execution

Rewrite the code execution using run_shell with a heredoc:

python3 << 'EOF'
# Your Python code here
import library_name
# ... rest of code
EOF

Step 3: Execute via run_shell

Call run_shell with the heredoc Python script:

command: python3 << 'EOF'
import reportlab
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

# Your library-dependent code here
c = canvas.Canvas("output.pdf", pagesize=letter)
c.drawString(100, 750, "Hello World")
c.save()
EOF

Example: PDF Generation Fallback

Sandbox attempt (fails):

# execute_code_sandbox call fails with:
# ModuleNotFoundError: No module named 'reportlab'

Shell fallback (works):

python3 << 'EOF'
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

c = canvas.Canvas("legal_memo.pdf", pagesize=letter)
c.setTitle("Legal Memorandum")
c.drawString(100, 750, "CONFIDENTIAL LEGAL MEMORANDUM")
c.save()
print("PDF created successfully")
EOF

Best Practices

  1. Use quoted heredoc (<< 'EOF') - Prevents variable expansion, keeping Python code intact
  2. Verify output - Check stdout/stderr from run_shell to confirm success
  3. Handle file paths - Ensure output files are written to accessible directories
  4. Test incrementally - For complex scripts, test in smaller chunks first
  5. Include error handling - Add try/except blocks to capture issues gracefully

Alternative: Inline Python Command

For simple one-liners or short scripts:

python3 -c "import reportlab; print(reportlab.__version__)"

Troubleshooting

If shell execution also fails:

  • Check if Python3 is available: which python3
  • Verify package installation: pip3 list | grep package_name
  • Try python instead of python3 (some systems differ)
  • Consider installing the package: pip3 install package_name
자주 묻는 질문

어떤 오류가 전환 신호인가요?

ModuleNotFoundError나 패키지에 대한 ImportError 같은 오류가 전환 신호입니다.

PDF 파일도 만들 수 있나요?

스킬은 reportlab 같은 라이브러리로 PDF를 만드는 것을 한 예로 언급합니다.

항상 작동하나요?

스킬은 셸에 패키지가 설치되어 있다고 가정하므로, 설치되어 있지 않으면 여전히 실패할 수 있습니다.

상세 정보

작성자의 원본 설명

Fallback to shell execution when sandbox fails for library-dependent Python code

repo: HKUDS/AgentPilot

인기도

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

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬