跳到正文
Skillpedia
通用编程7.8k · #12981

safe-script-execution

它能做什么

这项技能为 AI 智能体提供了一种手动方式,用于在其自动工具无法产生预期输出时创建并运行脚本。它适合希望清楚掌控每一步的人。

适用场景

  • ✓当代码沙箱或 shell 智能体反复未能产生你预期的输出的时候。
  • ✓当你希望智能体在创建任何文件之前,先确认其工作文件夹的时候。
  • ✓当脚本包含会破坏简单命令的引号或特殊字符的时候。

技能链接

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/safe-script-execution/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/safe-script-execution/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我的脚本在沙箱中一直失败。请用完整路径把它保存为文件并运行,然后告诉我输出是否正确。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会检查当前文件夹,使用带有唯一结束标记的 heredoc 将脚本写入文件,使其可执行,然后通过完整路径运行。之后它会先检查输出,再向你汇报。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Safe Script Execution Fallback

When to Use This Skill

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.

Step-by-Step Instructions

Step 1: Verify Working Directory

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.

Step 2: Create Script via Heredoc

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:

  • Use single quotes around heredoc delimiter ('EOF') to prevent shell variable expansion
  • If script contains the delimiter string, choose a different unique delimiter
  • For bash scripts containing special characters, escape $, backticks, and !

Step 3: Make Executable and Run with Explicit Path

chmod +x /full/path/to/script.py
/full/path/to/script.py

Always use the full absolute path, never rely on . or relative paths.

Step 4: Verify Output

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

Step 5: Error Handling

If execution fails:

  1. Check script syntax: python3 -m py_compile /path/to/script.py
  2. Check permissions: ls -l /path/to/script.py
  3. Check available disk space: df -h .
  4. Review stderr output carefully

Example: PDF Generation Fallback

# 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"

Anti-Patterns to Avoid

  • ❌ Don't use relative paths like ./script.py - always use absolute paths
  • ❌ Don't rely on unquoted heredoc delimiters if script contains variables
  • ❌ Don't skip verification steps - always confirm output exists and has expected size
  • ❌ Don't assume working directory - always pwd first

Troubleshooting Checklist

  • Working directory confirmed with pwd
  • Script file exists after heredoc creation (ls -l)
  • Script has execute permissions (chmod +x)
  • Output file exists with non-zero size (ls -lh)
  • File type verified (file command or type-specific inspection)
常见问题

为什么用完整路径运行脚本?

完整路径可以避免因相对路径或工作文件夹错误而产生的问题。

为什么 heredoc 使用带引号的结束标记?

引号可以防止 shell 改动脚本中的美元符号或其他符号。

如果脚本中包含结束标记的文字怎么办?

这项技能要求换一个唯一的标记,以免文件被提前截断。

详情

作者的原始描述

Fallback workflow for code execution when automated tools fail, using shell heredoc with verification

repo: HKUDS/AgentPilot

热度

GitHub 星标
7.8k
排名
#12981
许可证
MIT
更新时间
2026/11/1

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能