Skip to content
Skillpedia
General coding7.8k · #12882

fallback-python-execution

What it does

This skill is a backup method for running Python when the sandbox or a helper agent cannot do it. It is for people who need Python to create data or document files.

When to use it

  • ✓When the sandbox returns unknown errors or fails repeatedly.
  • ✓When I need Python to create spreadsheets, documents or data files.
  • ✓When a helper agent has been unable to run Python code correctly.

Skill link

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/fallback-python-execution/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/fallback-python-execution/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“The helper cannot run my Python script to make the spreadsheet. Please save the script to a file and run it directly.”

5 new skills a week. 1 minute to read.

How it works

The AI writes the complete Python code to a .py file, runs it with a shell command, checks that the expected files appear, and optionally deletes the script afterward.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Fallback Python Execution Pattern

When to Use

Use this pattern when:

  • execute_code_sandbox returns unknown errors or fails repeatedly
  • shell_agent cannot successfully execute Python code
  • You need to create files (spreadsheets, documents, data files) via Python
  • Direct delegated approaches prove unreliable in the current environment

Core Technique

Instead of delegating Python execution to agents, use this two-step inline approach:

  1. Write Python code to a .py file using write_file
  2. Execute the file using run_shell with python <script.py>

Step-by-Step Instructions

Step 1: Write Python Code to File

Use write_file to create a Python script with all necessary code inline:

write_file
path: /path/to/script.py
content: |
    import pandas as pd
    # Your complete Python code here
    df = pd.DataFrame({...})
    df.to_excel('output.xlsx', index=False)

Step 2: Execute via run_shell

Run the script directly:

run_shell
command: python /path/to/script.py

Step 3: Verify and Clean Up

  • Check the output for success/errors
  • Verify the expected files were created
  • Optionally remove the temporary script if no longer needed

Why This Works

This approach is more reliable because:

  • Avoids agent interpretation layers that can introduce errors
  • Provides direct control over execution environment
  • Gives clear error output for debugging
  • Bypasses sandbox delegation issues

Example: Excel File Creation

# Step 1: Write the script
write_file:
  path: create_report.py
  content: |
    import pandas as pd
    from openpyxl import Workbook
    
    # Create data
    data = {'Column1': [1, 2, 3], 'Column2': ['A', 'B', 'C']}
    df = pd.DataFrame(data)
    
    # Save to Excel
    df.to_excel('report.xlsx', index=False)
    print('Excel file created successfully')

# Step 2: Execute
run_shell:
  command: python create_report.py

Tips

  • Include error handling in your Python code for better debugging
  • Use absolute paths when possible to avoid working directory issues
  • Add print statements to track execution progress
  • Keep scripts self-contained with all imports at the top
  • For complex tasks, break into multiple scripts if needed

Troubleshooting

Issue Solution
Module not found Add pip install commands before python command
Permission errors Check file paths are writable
Script not found Use absolute path or cd to directory first
Output not created Check for Python errors in run_shell output
FAQ

Why avoid the helper agent?

The guide says this approach avoids extra interpretation layers that can introduce errors.

Can the script be deleted afterward?

Yes, removing the temporary script is an optional final step.

What should be checked at the end?

The output for success or errors, and whether the expected files were created.

Details

Original description by the author

Reliable Python execution workflow when execute_code_sandbox or shell_agent fail

repo: HKUDS/AgentPilot

Popularity

GitHub stars
7.8k
Ranking position
#12882
License
MIT
Updated
11/1/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills