Two-step script execution workflow for debugging when shell_agent and execute_code_sandbox consistently fail
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-fallback-script-execution-4b8ecec67b5a ,按照其中的说明把「fallback-script-execution」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Use this pattern when:
shell_agent fails repeatedly with unclear error messagesexecute_code_sandbox consistently errors or times outInstead of delegating execution to an agent or running inline code, use this two-step approach:
write_filerun_shell with python script.pyThis provides:
Use write_file to create a self-contained Python script:
write_file with:
path: "path/to/script_name.py"
content: |
#!/usr/bin/env python3
# Your complete script here
# Include imports, logic, and error handling
Best Practices:
Use run_shell to execute the script:
run_shell with:
command: "python path/to/script_name.py"
Best Practices:
shell_agent with:
task: "Load Excel file, calculate correlations, save results"
Result: Agent struggles with path handling, unclear errors
# Step 1: Write script
write_file with:
path: "correlation_analysis.py"
content: |
import pandas as pd
import sys
try:
# Load data
df = pd.read_excel('data.xlsx', sheet_name='Returns')
print(f"Loaded {len(df)} rows")
# Calculate correlation
corr = df.corr()
print(f"Correlation matrix shape: {corr.shape}")
# Save results
with pd.ExcelWriter('output.xlsx') as writer:
df.to_excel(writer, sheet_name='Returns')
corr.to_excel(writer, sheet_name='Correlation')
print("SUCCESS: output.xlsx created")
except Exception as e:
print(f"ERROR: {type(e).__name__}: {e}", file=sys.stderr)
sys.exit(1)
# Step 2: Execute script
run_shell with:
command: "python correlation_analysis.py"
run_shell with ls -la path/ to verify files existIf this pattern also fails:
run_shell with which python or python --versionrun_shell with ls -la script.pyrun_shell with /usr/bin/python script.py