Four-step recovery workflow for code execution failures when inline Python fails
56
63%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./benchmarks/gdpval/skills/python-execution-fallback/SKILL.mdThis 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.pyOr with error capture:
python script.py 2>&1 | tee execution.logThis 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 identificationc5a9c4b
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.