本文へスキップ
Skillpedia
一般的なプログラミング7.8k · #12981

safe-script-execution

できること

このスキルは、自動ツールが期待どおりの出力を出さないとき、AIエージェントにスクリプトを手動で作成して実行する方法を示します。各手順を明確に管理したい人向けです。

使う場面

  • ✓コードサンドボックスやシェルエージェントが、期待した出力を何度も出せないとき。
  • ✓エージェントがファイルを作成する前に、ワーキングフォルダーを確認してほしいとき。
  • ✓スクリプトに引用符や特殊文字が含まれ、単純なコマンドでは動かないとき。

スキルのリンク

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

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/safe-script-execution/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“サンドボックスでスクリプトが失敗し続けています。フルパスを使ってファイルに保存し、実行して、出力が正しいか教えてください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

エージェントは現在のフォルダーを確認し、一意の終了マーカーを付けたヒアドキュメントでスクリプトをファイルに書き出します。実行可能にしてフルパスで実行し、出力を確認してから結果を報告します。

技術的な内容(元の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)
よくある質問

なぜフルパスでスクリプトを実行するのですか?

相対パスや誤った作業フォルダーによるミスを防ぐためです。

ヒアドキュメントの終了マーカーに引用符を付けるのはなぜですか?

引用符があると、シェルがスクリプト内のドル記号などの記号を書き換えるのを防げるためです。

スクリプトの中に終了マーカーと同じ文字列があったらどうしますか?

スキルは、ファイルが途中で切れないように、別の一意なマーカーを選ぶよう述べています。

詳細

作者による元の説明

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

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル