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

execute-code-fallback

하는 일

이 스킬은 코드 샌드박스에 연결할 수 없거나 시간이 초과되면 셸에서 Python을 실행하도록 AI에게 안내합니다. 샌드박스 서비스가 멈춰도 코드가 실행되어야 하는 사람에게 맞습니다.

사용하는 경우

  • ✓코드 샌드박스가 사용할 수 없다거나 연결할 수 없다고 보고할 때.
  • ✓샌드박스가 두 번 이상 연속으로 시간 초과되거나 실패한 경우.
  • ✓실행 전에 추가 패키지를 설치해야 하는 코드일 때.

스킬 링크

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/execute-code-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/execute-code-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에게 요청하는 예시

“지금 코드 샌드박스가 작동하지 않습니다. Python 스크립트를 셸에서 실행해 주시고, 필요한 패키지는 먼저 설치해 주세요.”

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

작동 방식

AI는 pip으로 필요한 패키지를 설치한 뒤, 셸 명령으로 Python 코드를 실행합니다. 긴 스크립트에는 heredoc을 사용합니다.

기술 내용 (원본 SKILL.md)

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

Execute Code Fallback Pattern

When execute_code_sandbox fails due to e2b unavailability, immediately fall back to run_shell with embedded Python code. This ensures task continuity when the sandbox service is down.

When to Apply

Use this pattern when you observe:

  • execute_code_sandbox returns errors mentioning "e2b", "sandbox unavailable", or connection timeouts
  • Repeated sandbox execution failures (2+ attempts)
  • Error messages indicating the code execution environment is unreachable

Fallback Procedure

Step 1: Detect the Failure

Identify that execute_code_sandbox has failed. Common error indicators:

  • "e2b service unavailable"
  • "Sandbox connection failed"
  • "Execution environment not reachable"
  • Timeout errors during code execution

Step 2: Switch to run_shell with Embedded Python

Instead of:

execute_code_sandbox(code="...")

Use:

run_shell(command="python3 -c '...your Python code...'")

Step 3: Install Dependencies First (If Needed)

If your Python code requires external packages, install them first:

run_shell(command="pip install pandas requests matplotlib")

Then execute your main code:

run_shell(command="python3 << 'EOF'
import pandas as pd
import requests

# Your code here
print("Success")
EOF
")

Step 4: Use Heredoc for Multi-line Code

For complex Python scripts, use heredoc syntax for cleaner code:

run_shell(command="python3 << 'PYTHON_SCRIPT'
import json
import os

# Complex logic here
data = {'key': 'value'}
with open('output.json', 'w') as f:
    json.dump(data, f)

print('File created successfully')
PYTHON_SCRIPT
")

Complete Example

Scenario: You need to process a CSV file and generate a report.

Original approach (sandbox):

execute_code_sandbox(code="""
import pandas as pd
df = pd.read_csv('data.csv')
summary = df.describe()
print(summary)
""")

Fallback approach (run_shell):

# First install dependencies if needed
run_shell(command="pip install pandas --quiet")

# Then execute the code
run_shell(command="python3 << 'EOF'
import pandas as pd
df = pd.read_csv('data.csv')
summary = df.describe()
print(summary)
EOF
")

Important Considerations

  1. State Persistence: Unlike execute_code_sandbox, run_shell executions may not share state between calls. Save intermediate results to files if needed.

  2. Working Directory: Ensure you're operating in the correct directory. Use pwd to verify or include cd /path/to/workdir in your commands.

  3. Python Version: Use python3 explicitly to avoid ambiguity. Verify with python3 --version if needed.

  4. Error Handling: Check the stdout/stderr from run_shell to confirm success. Failed Python scripts will return non-zero exit codes.

  5. Security: Be cautious when embedding user-provided data into shell commands. Escape appropriately or use file-based input.

  6. Performance: For large computations, run_shell may be slower than sandbox. Consider breaking into smaller steps if timeouts occur.

Quick Reference

Task Sandbox Approach Fallback Approach
Simple calculation execute_code_sandbox(code="print(2+2)") run_shell(command="python3 -c 'print(2+2)'")
Install + run execute_code_sandbox(code="import pkg; ...") run_shell(command="pip install pkg && python3 -c '...'")
Multi-line script execute_code_sandbox(code="...") run_shell(command="python3 << 'EOF'...EOF")
File I/O execute_code_sandbox(code="...") run_shell(command="python3 << 'EOF'...EOF")

Recovery Checklist

  • Confirm execute_code_sandbox failure (not a code bug)
  • Switch to run_shell immediately
  • Install required packages with pip install
  • Use heredoc for multi-line Python
  • Verify output and handle errors
  • Save intermediate results to files if multi-step
자주 묻는 질문

어떤 오류가 전환을 일으키나요?

샌드박스 사용 불가, 연결 시간 초과, 실행 환경에 닿지 않음 같은 메시지를 가이드가 언급합니다.

패키지는 어떻게 추가하나요?

가이드는 주요 코드를 실행하기 전에 pip으로 먼저 설치합니다.

왜 heredoc을 쓰나요?

여러 줄로 된 스크립트를 셸 명령 하나로 실행할 수 있기 때문입니다.

상세 정보

작성자의 원본 설명

Fallback from execute_code_sandbox to run_shell when e2b sandbox is unavailable

repo: HKUDS/AgentPilot

인기도

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

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬