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

python-execution-fallback-9d4989

하는 일

이 스킬은 샌드박스 도구가 고장 났을 때 간단한 Python 코드를 실행하는 예비 방법을 AI 에이전트에게 줍니다. 짧은 코드에도 AI 도구가 알 수 없는 오류를 내는 사람에게 맞습니다.

사용하는 경우

  • ✓코드 샌드박스가 간단한 print 문에도 알 수 없는 오류를 낼 때.
  • ✓샌드박스가 응답하지 않는데 간단한 Python 계산이 필요할 때.
  • ✓AI의 컴퓨터에서 Python이 작동하는지 확인하고 싶은 경우.

스킬 링크

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-execution-fallback-9d4989/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-execution-fallback-9d4989/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분.

작동 방식

에이전트는 heredoc을 이용해 셸로 Python 코드를 보내 코드를 바로 Python에 전달합니다. 먼저 짧은 테스트 출력으로 Python이 있는지 확인합니다.

기술 내용 (원본 SKILL.md)

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

Python Execution Fallback

When to Use

Use this skill when execute_code_sandbox returns 'unknown error' or fails unexpectedly, even on simple Python code like print statements.

Solution

Switch to using run_shell with Python heredoc syntax instead of execute_code_sandbox.

Basic Syntax

python3 << 'EOF'
# Your Python code here
print("Hello World")
result = 2 + 2
print(f"Result: {result}")
EOF

How to Call

Instead of:

execute_code_sandbox(code="print('Hello')")

Use:

run_shell(command="python3 << 'EOF'\nprint('Hello')\nEOF")

For multi-line code, build the command string:

code = """
import json
data = {"status": "ok", "count": 42}
print(json.dumps(data))
"""
run_shell(command=f"python3 << 'EOF'\n{code}\nEOF")

Why This Works

  • run_shell executes commands directly in the shell environment, bypassing sandbox issues
  • Heredoc syntax (<< 'EOF') allows clean multi-line Python code without complex escaping
  • Single quotes around EOF prevent unwanted shell variable expansion
  • More reliable for simple to moderate Python execution tasks

Guidelines

  1. Always use single quotes around EOF ('EOF') to prevent variable expansion
  2. Test with a simple print statement first to verify Python is available
  3. For longer scripts, consider writing to a .py file first, then executing:
    run_shell(command="python3 /path/to/script.py")
    
  4. Capture stdout from run_shell to get Python output
  5. Handle errors by checking run_shell's stderr output

Example: Complete Workflow

# Step 1: Try execute_code_sandbox
try:
    result = execute_code_sandbox(code="print(2+2)")
except Exception as e:
    # Step 2: Fallback to run_shell with heredoc
    result = run_shell(command="python3 << 'EOF'\nprint(2+2)\nEOF")
    # Parse stdout to get the output
    output = result.stdout.strip()

Troubleshooting

Issue Solution
Python not found Use which python3 to verify installation
Heredoc not working Ensure single quotes around EOF delimiter
Complex imports fail Install required packages or write to .py file
Output not captured Check run_shell stdout, not return value
자주 묻는 질문

heredoc은 무엇인가요?

파일에 먼저 저장하지 않고도 여러 줄의 코드를 명령 하나로 프로그램에 전달하는 방법입니다.

긴 스크립트에도 쓸 수 있나요?

스킬은 긴 스크립트는 먼저 파일로 저장한 뒤 그 파일을 실행하라고 제안합니다.

EOF를 왜 작은따옴표로 감싸나요?

작은따옴표는 셸이 코드 안의 달러 기호나 다른 기호를 바꾸지 못하게 막습니다.

상세 정보

작성자의 원본 설명

Fallback method for executing Python when execute_code_sandbox fails with unknown errors

repo: HKUDS/AgentPilot

인기도

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

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬