Fallback workflow for code execution when automated tools fail, using shell heredoc with verification
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-safe-script-execution-30f652912ba2 ,按照其中的说明把「safe-script-execution」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Use this pattern when execute_code_sandbox or shell_agent repeatedly fails to produce expected outputs. This manual fallback provides explicit control over script creation and execution with built-in verification.
Before creating any scripts, confirm your current location and permissions:
pwd
ls -la
Document the absolute path. All subsequent file operations should use explicit paths from this point.
Use shell heredoc syntax to create scripts. This avoids issues with multi-line string escaping:
cat > /full/path/to/script.py << 'HEREDOC_END'
#!/usr/bin/env python3
# Your script content here
# Single quotes around delimiter prevent variable expansion
print("Hello from script")
HEREDOC_END
Key escaping rules:
'EOF') to prevent shell variable expansion$, backticks, and !chmod +x /full/path/to/script.py
/full/path/to/script.py
Always use the full absolute path, never rely on . or relative paths.
Confirm files were created and inspect their properties:
# Check file exists with size
ls -lh /full/path/to/output.file
# For PDFs, inspect metadata
pdfinfo /full/path/to/output.pdf 2>/dev/null || file /full/path/to/output.pdf
# For Word docs, check file type
file /full/path/to/output.docx
If execution fails:
python3 -m py_compile /path/to/script.pyls -l /path/to/script.pydf -h .# Step 1: Verify directory
pwd
ls -la
# Step 2: Create Python script
cat > /workspace/generate_pdf.py << 'SCRIPT_END'
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
c = canvas.Canvas("/workspace/output.pdf", pagesize=letter)
c.drawString(100, 750, "Generated PDF")
c.save()
SCRIPT_END
# Step 3: Execute
chmod +x /workspace/generate_pdf.py
python3 /workspace/generate_pdf.py
# Step 4: Verify
ls -lh /workspace/output.pdf
pdfinfo /workspace/output.pdf 2>/dev/null || echo "PDF created, pdfinfo unavailable"
./script.py - always use absolute pathspwd firstpwdls -l)chmod +x)ls -lh)file command or type-specific inspection)