本文へ移動
cccskills
無料GitHub で公開

python-execution-fallback-9d4989

Fallback method for executing Python when execute_code_sandbox fails with unknown errors

インストール方法を見る

含まれるファイル(2)

  • SKILL.md2.4 KB
  • .skill_id46 B

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

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

IssueSolution
Python not foundUse which python3 to verify installation
Heredoc not workingEnsure single quotes around EOF delimiter
Complex imports failInstall required packages or write to .py file
Output not capturedCheck run_shell stdout, not return value

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Incremental audio production with duration mismatch handling, adaptive stem extension, and pre-mix alignment verification

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

Incremental audio production with duration alignment handling, per-stem verification, and adaptive extension strategies

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

Create serverless API proxy endpoints that hide API keys and provide a unified backend for the dashboard frontend. Designed for Vercel deployment.

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

End-to-end audio production workflow with stems, effects, archiving, and verification

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

Handle cascading data retrieval tool failures by falling back to embedded knowledge generation

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

Fallback pattern for executing Python code when execute_code_sandbox fails

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

HKUDS のスキルをすべて見る

このスキルの問題を報告する