Skip to content
cccskills
FreePublished on GitHub

python-shell-fallback

Continue library-dependent Python tasks when sandbox execution fails by switching to a shell script. Covers recognizing import errors, preserving script text, checking execution output, and troubleshooting package availability for tasks such as PDF generation or visualization.

OriginalShow the original description

Fallback to shell execution when sandbox fails for library-dependent Python code

See how to install

Good for

  • Retrying Python code after missing-library errors
  • Continuing PDF generation through shell execution
  • Running visualization code with installed packages
  • Checking Python and package availability

Files included (2)

  • SKILL.md2.9 KB
  • .skill_id35 B

SKILL.md (original)

Review the instructions the agent will receive before you install.

Python Shell Fallback

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.

When to Use This Pattern

Apply this skill when:

  • execute_code_sandbox returns errors related to missing libraries (e.g., ModuleNotFoundError)
  • The code requires packages that may not be installed in the sandbox environment
  • You need PDF generation, data visualization, or other library-heavy operations
  • Previous sandbox execution attempts have failed with import errors

How to Implement

Step 1: Identify the Failure

Check if the sandbox error indicates a library/dependency issue:

  • ModuleNotFoundError: No module named 'xxx'
  • ImportError: cannot import name 'xxx'
  • Similar package-related errors

Step 2: Convert to Shell Execution

Rewrite the code execution using run_shell with a heredoc:

python3 << 'EOF'
# Your Python code here
import library_name
# ... rest of code
EOF

Step 3: Execute via run_shell

Call run_shell with the heredoc Python script:

command: python3 << 'EOF'
import reportlab
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

# Your library-dependent code here
c = canvas.Canvas("output.pdf", pagesize=letter)
c.drawString(100, 750, "Hello World")
c.save()
EOF

Example: PDF Generation Fallback

Sandbox attempt (fails):

# execute_code_sandbox call fails with:
# ModuleNotFoundError: No module named 'reportlab'

Shell fallback (works):

python3 << 'EOF'
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

c = canvas.Canvas("legal_memo.pdf", pagesize=letter)
c.setTitle("Legal Memorandum")
c.drawString(100, 750, "CONFIDENTIAL LEGAL MEMORANDUM")
c.save()
print("PDF created successfully")
EOF

Best Practices

  1. Use quoted heredoc (<< 'EOF') - Prevents variable expansion, keeping Python code intact
  2. Verify output - Check stdout/stderr from run_shell to confirm success
  3. Handle file paths - Ensure output files are written to accessible directories
  4. Test incrementally - For complex scripts, test in smaller chunks first
  5. Include error handling - Add try/except blocks to capture issues gracefully

Alternative: Inline Python Command

For simple one-liners or short scripts:

python3 -c "import reportlab; print(reportlab.__version__)"

Troubleshooting

If shell execution also fails:

  • Check if Python3 is available: which python3
  • Verify package installation: pip3 list | grep package_name
  • Try python instead of python3 (some systems differ)
  • Consider installing the package: pip3 install package_name

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Prepare audio stems, the separate parts of a track, for mixing by matching their durations with silence, loops, or crossfades. Verify each generated and processed file before moving to the next production step.

  • Match audio parts with different durations
  • Extend drums and melodic parts using suitable methods
  • Check audio specifications before mixing
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

Produce audio in separate stems, meaning individual instrument tracks, and verify each output as you go. Align track lengths with silence, loops, or crossfades, then apply effects, mix a master, and package the files.

  • Align instrument tracks to a reference audio file
  • Choose how to extend tracks that are too short
  • Verify audio properties after generation and effects
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

Build serverless endpoints that relay external API requests for a dashboard while keeping API keys on the server. Includes Vercel examples for input checks, caching, cross-origin access, and consistent JSON responses.

  • Connect a dashboard to external APIs without exposing API keys
  • Create endpoints for stock quotes and news
  • Standardize API responses and error handling
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

Produce a master track and separate audio parts through a structured Python workflow. Apply filters and reverb, export WAV files with consistent settings, package them in a ZIP archive, and check that the deliverables meet the requested specifications.

  • Export a master track with separate audio parts
  • Apply filters and reverb to audio
  • Check duration and format across deliverables
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

Keep document creation moving when web searches and page retrieval repeatedly fail. The skill preserves the original task, uses the model’s existing knowledge, and clearly identifies information that could not be checked against external sources.

  • Continue drafting after repeated web retrieval failures
  • Preserve task requirements during network errors
  • Mark information that could not be externally verified
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

When Python execution repeatedly fails in execute_code_sandbox, use a file-based alternative: save the script, run it through the shell, and capture results or errors. The guidance covers paths, imports, timeouts, structured output, and optional cleanup.

  • Retry Python work through the shell after repeated sandbox failures
  • Run longer tasks with an adjusted timeout
  • Execute Python work that needs multiple files or system utilities
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

See all skills by HKUDS

Report a problem with this skill