Fallback workflow for running code via file write and shell when sandbox execution fails
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-fallback-code-execution-8ec236716612 ,按照其中的说明把「fallback-code-execution」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
This skill defines a robust workaround for executing code (specifically Python) when the primary execute_code_sandbox tool fails repeatedly with unknown or transient errors. Instead of continuing to retry the failing tool, the agent switches to a manual file-write and shell-execution pattern.
Activate this workflow when:
execute_code_sandbox fails 2 or more times consecutively for the same logic.Use the write_file tool to save the Python script to a specific path in the workspace.
.py (e.g., scripts/generate_report.py).requirements.txt is updated or installed via shell beforehand.Example:
tool: write_file
path: workspace/scripts/process_data.py
content: |
import sys
# ... script logic ...
print("Success")
Use the run_shell tool to execute the script using the system Python interpreter.
python3 <path_to_script> or python <path_to_script>.Example:
tool: run_shell
command: python3 scripts/process_data.py
0.__file__ to avoid working directory issues.print() statements in the Python script to log progress, as shell output capture is sometimes more reliable than sandbox return values.Problem: execute_code_sandbox times out while generating a PDF.
Solution:
generate_pdf.py to workspace/scripts/.python3 workspace/scripts/generate_pdf.py via run_shell.output.pdf exists in the workspace.