Fallback method for executing Python when execute_code_sandbox fails with unknown errors
Use this skill when execute_code_sandbox returns 'unknown error' or fails unexpectedly, even on simple Python code like print statements.
Switch to using run_shell with Python heredoc syntax instead of execute_code_sandbox.
python3 << 'EOF'
# Your Python code here
print("Hello World")
result = 2 + 2
print(f"Result: {result}")
EOF
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")
run_shell executes commands directly in the shell environment, bypassing sandbox issues<< 'EOF') allows clean multi-line Python code without complex escaping'EOF') to prevent variable expansion.py file first, then executing:
run_shell(command="python3 /path/to/script.py")
# Step 1: Try execute_code_sandbox