Fallback pattern for when execute_code_sandbox fails - write script to file and execute directly with run_shell
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-sandbox-execution-fallback-238489-78fb5fa4c976 ,按照其中的说明把「sandbox-execution-fallback-238489」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
This skill provides a reliable fallback pattern when execute_code_sandbox fails for code execution tasks (especially PDF generation, complex file operations, or library-dependent tasks).
Use this fallback pattern when:
execute_code_sandbox returns errors or fails to produce expected outputInstead of executing code directly in the sandbox, use write_file to create a standalone Python script:
Use write_file to create a script (e.g., script.py) with your complete Python code.
Run the script using run_shell with Python:
Use run_shell with command: python3 script.py
Check that the script executed successfully and produced the expected files or output.
Instead of this (sandbox execution):
execute_code_sandbox with code using libraries like reportlab, fpdf, etc.
Do this (fallback pattern):
# Step 1: Create the script
write_file:
path: generate_pdf.py
content: |
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
def create_pdf(filename):
c = canvas.Canvas(filename, pagesize=letter)
c.drawString(100, 750, "Hello World")
c.save()
create_pdf("output.pdf")
# Step 2: Execute directly
run_shell:
command: python3 generate_pdf.py
If run_shell also fails:
run_shell command: python3 --versionrun_shell command: pip3 install package_nameThis pattern bypasses sandbox limitations by:
This skill captures a genuinely reusable pattern that: