Pi Agent: Security & Project Trust

最終更新:2026-08-31

--- title: "セキュリティとプロジェクト信頼" description: "Pi Agentのセキュリティモデルを理解し、権限制御、プロジェクト信頼メカニズム、ツールサンドボックスを学びます。" order: 13 lang: ja

Agentはあなたの代わりにコマンドを実行できる——あるいは損害を与えることも。セキュリティメカニズムが「ブレーキ」だ。


1. セキュリティモデル概要

Pi Agentのセキュリティは3層モデルに基づいています:

TEXT 📖 参照専用
セキュリティ3層モデル
├── 第1層:プロジェクト信頼 — Agentがプロジェクトにアクセスできるか
├── 第2層:ツール権限 — どのツールが許可されているか
└── 第3層:実行サンドボックス — ツール実行のセキュリティ境界

2. プロジェクト信頼

(1) 信頼レベル

レベル 説明 許可される操作
untrusted 信頼なし チャットのみ、ファイル/コマンドアクセス不可
readonly 読み取り専用 プロジェクトファイルの読み取り、変更不可
trusted 完全信頼 ファイルの読み書き、コマンド実行
restricted 制限付き カスタム許可リスト操作

(2) 信頼レベルの設定

BASH
pi-agent trust set ./my-project --level trusted
pi-agent trust list

(3) 初回インタラクションプロンプト

新しいプロジェクトディレクトリでPi Agentを使用する際:

TEXT 📖 参照専用
New project detected: /home/alice/my-project
Trust this project? [y/N]

trusted    - Full access (read/write files, execute commands)
readonly   - Read-only access
untrusted  - No access

Select trust level:

(4) Python API

PYTHON
from pi_agent import Agent, TrustLevel

agent = Agent(
    name="safe_agent",
    project_path="./my-project",
    trust_level=TrustLevel.READONLY
)

3. ツール権限

(1) 危険度レベル

レベル 例ツール デフォルト状態
Safe calculator, search 自動有効
Medium file_reader 確認が必要
Dangerous file_write, shell 明示的な認可が必要

(2) 権限設定

YAML
permissions:
  tools:
    safe: auto
    medium: confirm
    dangerous: deny

  allow:
    - calculator
    - search
    - file_reader
  deny:
    - shell
    - file_write

  confirm_dangerous: true
  confirm_file_write: true
  confirm_shell: true

(3) 実行時確認

TEXT 📖 参照専用
you> Delete all temporary files
Agent wants to execute: rm -rf /tmp/project_*
Allow? [y/N/a(always)]

4. 実行サンドボックス

PYTHON
from pi_agent import Agent

agent = Agent(
    name="sandboxed",
    sandbox=True,
    sandbox_dir="/tmp/pi_sandbox",
    allowed_commands=["python", "pytest"],
    max_execution_time=30
)

ファイルシステムの分離:

PYTHON
agent = Agent(
    sandbox=True,
    sandbox_dir="./workspace/sandbox",
    allowed_paths=["./data/", "./output/"]
)

ネットワーク制限:

PYTHON
agent = Agent(
    sandbox=True,
    network_access=False,
    allowed_domains=["api.github.com"]
)

5. セキュリティベストプラクティス

PYTHON
agent = Agent(
    audit_log=True,
    audit_file="./audit.log"
)

❓ よくある質問

Q 信頼を取り消せますか?
A はい。pi-agent trust set ./project --level untrusted または ~/.pi-agent/trust/ のファイルを削除してください。
Q shellツールを完全に無効にできますか?
A はい。設定に deny: [shell] を追加するか、ツールリストに含めないでください。推奨されます。
Q サンドボックスはパフォーマンスに影響しますか?
A ファイルシステムの分離はほぼ影響ありません。ネットワーク制限はインターネットを必要とするツールに影響する可能性があります。

📖 まとめ


📝 練習問題

  1. 基礎(難易度:⭐): プロジェクトにreadonly信頼を設定し、制限モードでのAgentの動作を観察してください。
  2. 中級(難易度:⭐⭐): 特定のディレクトリのみ読み取り、Pythonコマンドのみ実行できるサンドボックスAgentを設定してください。
  3. 上級(難易度:⭐⭐⭐): 完全な権限マトリックスを含むセキュリティポリシーファイルを書き、監査ログで検証してください。
Web-Tutorial.com

Web-Tutorial 技術チーム

複数の開発者によって共同維持されているプログラミングチュートリアルプラットフォーム。各チュートリアルは専門分野の開発者が執筆・レビューしています。正確で信頼性の高いコンテンツを目指しています — 問題を見つけた場合はお知らせください。

100%