Fallback to shell execution when sandbox fails for library-dependent Python code
When execute_code_sandbox fails for Python code that depends on external libraries, use run_shell with a heredoc Python script as a reliable fallback. The shell environment typically has better access to installed packages and system configuration than the sandbox.
Apply this skill when:
execute_code_sandbox returns errors related to missing libraries (e.g., ModuleNotFoundError)Check if the sandbox error indicates a library/dependency issue:
ModuleNotFoundError: No module named 'xxx'ImportError: cannot import name 'xxx'Rewrite the code execution using run_shell with a heredoc:
python3 << 'EOF'
# Your Python code here
import library_name
# ... rest of code
EOF
Call run_shell with the heredoc Python script: