safe-script-execution
Skill này làm gì
Skill này cho AI agent một cách thủ công để tạo và chạy script khi các công cụ tự động không cho ra đầu ra như mong đợi. Nó dành cho những người muốn kiểm soát rõ ràng từng bước.
Khi nào nên dùng
- ✓Khi sandbox mã hoặc shell agent liên tục không cho ra đầu ra đúng như bạn mong đợi.
- ✓Khi bạn muốn agent xác nhận thư mục làm việc trước khi tạo bất kỳ file nào.
- ✓Khi một script chứa dấu nháy hoặc ký tự đặc biệt làm hỏng các lệnh đơn giản hơn.
Liên kết skill
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/safe-script-execution/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Script của tôi liên tục lỗi trong sandbox. Hãy lưu nó thành file với đường dẫn đầy đủ, chạy nó và cho tôi biết đầu ra có đúng không.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent kiểm tra thư mục hiện tại, ghi script vào file bằng heredoc với một dấu kết thúc duy nhất, cấp quyền thực thi và chạy nó bằng đường dẫn đầy đủ. Sau đó nó kiểm tra đầu ra trước khi báo cáo.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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:
- Check script syntax:
python3 -m py_compile /path/to/script.py - Check permissions:
ls -l /path/to/script.py - Check available disk space:
df -h . - 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
pwdfirst
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 (
filecommand or type-specific inspection)
Câu hỏi thường gặp
Tại sao dùng đường dẫn đầy đủ để chạy script?
Đường dẫn đầy đủ tránh được lỗi do đường dẫn tương đối hoặc sai thư mục làm việc.
Tại sao dấu kết thúc heredoc được đặt trong dấu nháy?
Dấu nháy ngăn shell thay đổi dấu đô la hoặc các ký hiệu khác bên trong script.
Nếu script có chứa chính dấu kết thúc thì sao?
Skill yêu cầu chọn một dấu kết thúc khác, duy nhất, để file không bị cắt ngắn.
Chi tiết
Mô tả gốc của tác giả
Fallback workflow for code execution when automated tools fail, using shell heredoc with verification
repo: HKUDS/AgentPilot
Độ phổ biến
- Sao GitHub
- 7.8k
- Vị trí xếp hạng
- #12981
- Giấy phép
- MIT
- Cập nhật
- 1/11/2026
Bình luận
- …
Thêm skill từ kho mã này
agentpilot
7.8kGiúp agent của bạn cải thiện dự án từng bước bằng cách chuẩn bị tác vụ và chạy vòng lặp AgentPilot, gồm đề xuất, kiểm thử và chấm điểm thay đổi.
openspace
7.8kGiúp agent của bạn thiết lập OpenSpace, công cụ lưu và lấy lại skill của agent, rồi kết nối nó với ứng dụng AI của bạn qua MCP.
rsi-arena
7.8kGiúp agent của bạn thiết lập và chạy các bài kiểm thử benchmark AI chuẩn, như AIME và Terminal-Bench, để so sánh các phương pháp cải tiến khác nhau.
experiment-guide
7.8kGiúp agent của bạn lên kế hoạch các thí nghiệm nhỏ, đọc kết quả và ghi lại phát hiện khi tìm cách cải thiện một chương trình.
Skill tương tự
diffs
394kGiúp agent của bạn tạo một diff có thể chia sẻ về các chỉnh sửa, dưới dạng liên kết xem hoặc file ảnh, thay vì một bản tóm tắt viết tay.
coding-agent
394kGiúp agent của bạn giao một việc lập trình lớn cho Codex, Claude Code hoặc OpenCode chạy nền, rồi theo dõi tiến độ của nó.
gh-issues
394kGiúp agent của bạn tìm issue trên GitHub, chọn những issue cần xử lý và mở pull request với bản sửa, kể cả theo dõi nhận xét đánh giá.