Skip to content
cccskills
FreePublished on GitHub

code-execution-fallback-e81068

Continue Python tasks after repeated sandbox failures by saving code as a script and running it through the shell, a command interface. The workflow covers execution checks, result retrieval, and optional cleanup.

OriginalShow the original description

Fallback workflow for executing Python code when execute_code_sandbox fails repeatedly

See how to install

Good for

  • Continuing data processing after repeated sandbox errors
  • Saving execution results to files for later retrieval
  • Checking script errors and exit codes

Files included (2)

  • SKILL.md4.1 KB
  • .skill_id44 B

SKILL.md (original)

Review the instructions the agent will receive before you install.

Code Execution Fallback Workflow

When to Use

Use this skill when execute_code_sandbox fails repeatedly (2+ attempts) with unknown, persistent, or unexplained errors. This fallback approach uses write_file + run_shell to save Python scripts to disk and execute them via command line, which has proven more reliable in certain failure scenarios.

Step-by-Step Instructions

Step 1: Detect Repeated Failures

Monitor execute_code_sandbox attempts. After 2 consecutive failures with errors like:

  • "Unknown error"
  • Timeout errors
  • Unexplained execution failures
  • Sandbox environment issues

Switch to the fallback workflow immediately.

Step 2: Write the Python Script to File

Use write_file to save your Python code as a .py file in the working directory:

write_file(
    path="script.py",
    content="""
import sys
import json

# Your Python code here
def main():
    # Your logic
    result = {"status": "success", "data": "example"}
    print(json.dumps(result))

if __name__ == "__main__":
    main()
"""
)

Tips:

  • Use clear, self-contained code that doesn't rely on sandbox-specific paths
  • Include error handling and informative print statements
  • Save output to files if needed for later retrieval

Step 3: Execute via Shell

Use run_shell to execute the Python script via command line:

run_shell(
    command="python3 script.py",
    timeout=60  # Adjust timeout as needed
)

Alternative commands:

  • python script.py - if python3 alias isn't available
  • python3 -u script.py - for unbuffered output
  • python3 script.py arg1 arg2 - with arguments

Step 4: Verify Output and Results

Check the stdout/stderr from run_shell to:

  • Confirm execution succeeded (exit code 0)
  • Inspect printed output or results
  • Identify any new errors (different from sandbox errors)

If the script writes output files, use read_file to retrieve results.

Step 5: Clean Up (Optional)

Remove temporary script files if they won't be reused:

run_shell(command="rm script.py")

Complete Example

Scenario: execute_code_sandbox failed twice while trying to process data.

Fallback execution:

# Step 1: Write the processing script
write_file(
    path="process_data.py",
    content="""
import pandas as pd
import json

def process():
    data = [1, 2, 3, 4, 5]
    result = {"sum": sum(data), "count": len(data)}
    print(json.dumps(result))
    
    # Also save to file for reliability
    with open("result.json", "w") as f:
        json.dump(result, f)

if __name__ == "__main__":
    process()
"""
)

# Step 2: Execute via shell
output = run_shell(command="python3 process_data.py")

# Step 3: Read results from file
results = read_file(file_path="result.json", filetype="json")

Troubleshooting

IssueSolution
python3: command not foundTry python instead, or check available interpreters with which python
Permission deniedEnsure the working directory is writable; write_file creates files in workspace by default
Module not foundInstall dependencies via run_shell(command="pip install package_name") before execution
Script hangsIncrease timeout parameter in run_shell
Output too longRedirect output to file within the script and read it separately

Best Practices

  1. Always include error handling in scripts to capture failures gracefully
  2. Write results to files in addition to printing, for reliable retrieval
  3. Use descriptive filenames to avoid conflicts (e.g., task_specific_script.py)
  4. Keep scripts self-contained - avoid dependencies on sandbox environment variables
  5. Log execution details for debugging: print(f"Step X complete: {value}")

When NOT to Use This Fallback

  • When sandbox isolation is required for security
  • When the task explicitly requires execute_code_sandbox
  • When execute_code_sandbox succeeds consistently (no need to add complexity)
  • When working with sensitive data that shouldn't persist to disk

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