fallback-python-execution
Reliable Python execution workflow when execute_code_sandbox or shell_agent fail
- License 许可
- MIT
- 最近更新
- 2026-04-06
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- fallback-python-execution
- description
- Reliable Python execution workflow when execute_code_sandbox or shell_agent fail
02 资源文件 1
- 其他.skill_id39 B
03 SKILL.md 正文
Fallback Python Execution Pattern
When to Use
Use this pattern when:
execute_code_sandboxreturns unknown errors or fails repeatedlyshell_agentcannot 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:
- Write Python code to a
.pyfile usingwrite_file - Execute the file using
run_shellwithpython <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 |
04 同仓库更多 Skills
zip-export-deliverable
Ensures codebase deliverables are properly exported as ZIP archives through a dedicated finalization step
zip-deliverable-finalization
Ensure codebase deliverables are properly packaged as ZIP exports in a dedicated final step
zero-iteration-failure-analysis
Identify and handle agent failures with 0 iterations as pre-execution system issues
write-file-fallback-report
Generate professional documents using write_file when primary data sources fail, leveraging embedded domain knowledge instead of external retrieval
fallback-doc-with-delegation
Generate professional documents after tool failures using shell_agent for complex formats or write_file for simple text/markdown
context-anchored-fallback-report
Generate documents with write_file when retrieval tools fail, with explicit guardrails against task context drift