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

sandbox-fallback-python-e5d7ae

하는 일

이 스킬은 샌드박스가 시작되거나 연결되지 않을 때 AI 에이전트가 셸로 Python 코드를 실행하는 방법을 설명합니다. reportlab이나 pandas 같은 라이브러리를 쓰는 사람을 위한 스킬입니다.

사용하는 경우

  • ✓샌드박스가 초기화, 시작 또는 연결 오류를 보일 때.
  • ✓짧은 스크립트를 셸에서 바로 실행해야 할 때.
  • ✓긴 스크립트는 파일로 저장하고 더 긴 제한 시간으로 실행해야 할 때.

스킬 링크

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

AI에게 요청하는 예시

“샌드박스가 시작되지 않습니다. reportlab으로 제 PDF 청구서를 만들도록 셸에서 스크립트를 실행해 주세요.”

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

작동 방식

짧은 코드는 에이전트가 셸 명령 안에 heredoc으로 넣어 실행합니다. 긴 코드는 임시 파일에 쓰고 실행하며, 필요하면 작업에 더 많은 시간을 줍니다.

기술 내용 (원본 SKILL.md)

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

Python Sandbox Fallback Pattern

When to Use

Use this pattern when execute_code_sandbox fails with e2b/sandbox initialization errors, especially when running Python code that requires external libraries like reportlab, pandas, numpy, etc.

Common Failure Indicators

Detect these error patterns to trigger the fallback:

  • e2b initialization errors
  • sandbox creation/creation timeout failures
  • container startup errors
  • Connection/refusal errors from sandbox service

The Fallback Pattern

Basic Heredoc Approach

For short scripts, use a Python heredoc directly in run_shell:

run_shell(
    command="""python3 << 'EOF'
import sys
print(f"Python version: {sys.version}")
# Your code here
EOF
""",
    timeout=60
)

File-Based Approach for Complex Scripts

For longer scripts or when you need to preserve state across multiple executions:

# Step 1: Write the script to a temporary file
script_content = '''
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
import os

# Your code here
'''

run_shell(command=f"cat > /tmp/script.py << 'SCRIPT_EOF'\n{script_content}\nSCRIPT_EOF")

# Step 2: Execute the script
result = run_shell(command="python3 /tmp/script.py", timeout=120)

Key Considerations

Timeouts

  • run_shell typically needs longer timeouts than execute_code_sandbox
  • Use timeout=60 for simple scripts
  • Use timeout=120 or higher for library-heavy operations (PDF generation, data processing)

Library Availability

  • Verify required libraries are installed in the shell environment
  • Install missing libraries first if needed:
    run_shell(command="pip install reportlab", timeout=60)
    

Error Handling

  • Capture and inspect run_shell output for Python errors
  • Check stderr for import failures or runtime exceptions

Working Directory

  • Files created via run_shell are in the current working directory by default
  • Use absolute paths or os.getcwd() to reference files reliably

Example: PDF Generation with reportlab

# FALLBACK VERSION (when execute_code_sandbox fails):

pdf_code = """
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch

def create_memo(filename):
    c = canvas.Canvas(filename, pagesize=letter)
    c.drawString(1*inch, 10*inch, "Legal Memorandum")
    c.save()
    print(f"Created {filename}")

create_memo('/workspace/output.pdf')
"""

# Write script to file
run_shell(command=f"cat > /tmp/create_pdf.py << 'PYEOF'\n{pdf_code}\nPYEOF")

# Execute and verify
run_shell(command="python3 /tmp/create_pdf.py", timeout=120)

# Verify output exists
run_shell(command="ls -la /workspace/output.pdf", timeout=30)

Comparison Table

Aspect execute_code_sandbox run_shell (fallback)
Isolation High (containerized) Low (host environment)
Reliability Can fail with e2b errors More reliable
Library Access Pre-configured sandbox Depends on host
Timeout Default 30s Configurable
File Access ARTIFACT_PATH convention Direct filesystem

Migration Checklist

When switching from execute_code_sandbox to run_shell:

  • Increase timeout values (typically 2-4x)
  • Convert ARTIFACT_PATH references to actual file paths
  • Add explicit file verification steps after execution
  • Handle potential library import errors
  • Test script execution in shell environment first
자주 묻는 질문

제한 시간을 왜 길게 잡나요?

스킬은 셸 실행이 보통 샌드박스 실행보다 더 많은 시간이 필요하다고 설명합니다.

임시 파일은 어디에 보관되나요?

스킬의 예시는 임시 폴더에 파일을 쓰지만, 에이전트가 다른 위치를 고를 수도 있습니다.

어떤 라이브러리를 언급하나요?

코드에 필요할 수 있는 예로 reportlab, pandas, numpy를 언급합니다.

상세 정보

작성자의 원본 설명

Fallback to run_shell with Python heredoc when execute_code_sandbox fails

repo: HKUDS/AgentPilot

인기도

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

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬