with one click
python-execution-fallback
Four-step recovery workflow for code execution failures when inline Python fails
Menu
Four-step recovery workflow for code execution failures when inline Python fails
Delegate tasks to OpenSpace — a full-stack autonomous worker for coding, DevOps, web research, and desktop automation, backed by an extensive MCP tool and skill library. Skills auto-improve through use, reducing token consumption over time. A cloud community lets agents share and collectively evolve reusable skills.
Incremental audio production with duration mismatch handling, adaptive stem extension, and pre-mix alignment verification
Audio production with diagnostic analysis, timecode parsing from documents, and verified export workflow
Incremental audio production with duration alignment handling, per-stem verification, and adaptive extension strategies
Step-by-step audio production with per-stem verification, timing alignment, and incremental quality gates
End-to-end audio production workflow with stems, effects, archiving, and verification
| name | python-execution-fallback |
| description | Four-step recovery workflow for code execution failures when inline Python fails |
This skill provides a systematic debugging approach when inline Python code execution fails, particularly in heredoc or shell_agent contexts.
When Python code execution fails, follow this recovery workflow:
.py fileApply this pattern when:
Try executing Python code inline first (using execute_code_sandbox or similar):
# Example: Attempt inline execution
import pandas as pd
import openpyxl
df = pd.read_excel("input.xlsx")
# Process data...
df.to_excel("output.xlsx", index=False)
If this succeeds, proceed. If it fails, move to Step 2.
When inline execution fails, write the complete script to a persistent file:
# Capture the script content
script_content = '''
import pandas as pd
import openpyxl
import sys
try:
# Your original code here
df = pd.read_excel("input.xlsx")
# Processing logic
result_df = df.groupby("category").sum()
# Output
result_df.to_excel("output.xlsx", index=False)
print("SUCCESS: File generated")
except Exception as e:
print(f"ERROR: {e}", file=sys.stderr)
sys.exit(1)
'''
# Write to file
with open("script.py", "w") as f:
f.write(script_content)
print("Script written to script.py")
Run the saved script using shell execution:
python script.py
Or with error capture:
python script.py 2>&1 | tee execution.log
This approach:
Verify the results are correct:
# Validation script
import pandas as pd
import os
# Check file exists
if os.path.exists("output.xlsx"):
df = pd.read_excel("output.xlsx")
print(f"Rows: {len(df)}, Columns: {len(df.columns)}")
print(df.head())
print("VALIDATION: PASSED")
else:
print("VALIDATION: FAILED - Output file missing")
# Full fallback workflow example
def generate_spreadsheet_fallback(data, output_path):
"""Generate spreadsheet with fallback workflow"""
# Step 1: Try inline
inline_script = f'''
import pandas as pd
data = {data}
df = pd.DataFrame(data)
df.to_excel("{output_path}", index=False)
'''
try:
# Attempt inline execution
result = execute_code_sandbox(code=inline_script)
if "error" not in result.lower():
return "SUCCESS_INLINE"
except Exception as e:
pass
# Step 2: Write to file
file_script = f'''
import pandas as pd
import sys
try:
data = {data}
df = pd.DataFrame(data)
df.to_excel("{output_path}", index=False)
print("SUCCESS")
except Exception as e:
print(f"ERROR: {{e}}", file=sys.stderr)
sys.exit(1)
'''
with open("generate.py", "w") as f:
f.write(file_script)
# Step 3: Execute file
shell_result = run_shell(command="python generate.py")
# Step 4: Validate
if os.path.exists(output_path):
return "SUCCESS_FILE"
else:
return "FAILED"
This pattern helps resolve:
retry-with-modification for iterative debuggingoutput-validation-check for result verificationerror-log-analysis for root cause identification