Python SDK
対応モード: Hosted Hybrid Local 利用可能なプラン: Free Solo Teams
英語の原文 -- 翻訳は技術レビュー待ちです
The Control Zero Python SDK provides deterministic policy enforcement for AI agents running in Python environments. A deny stops the guarded call before it executes. Hosted policies arrive as signed bundles that are verified before use, and the SDK fails closed by default when it cannot establish coverage.
変更できないアプリケーションにはゲートウェイプロキシを、開発者向けの AI ツールにはコーディングフックを使用します。Python アプリケーションのコードを自分で管理できる場合に、この SDK を使用します。
インストール
pip install controlzero
要件:
- Python 3.9 以降
- 追加のシステム依存関係なし
クイックスタート
デプロイモードを選択します。
- Hosted
- Hybrid
- Local
Hosted ポリシーはダッシュボードから取得されます。
英語の原文 -- 翻訳は技術レビュー待ちです
Audit in cloud.
ほとんどのチームに推奨します。
from controlzero import Client
# SDK fetches your signed policy bundle on first call.
# Manages audit automatically. No local config needed.
client = Client(api_key="cz_live_your_api_key_here")
# Or use env var: export CONTROLZERO_API_KEY="cz_live_..."
インストール: pip install controlzero(クラウドモードの依存関係は 1.4.3 以降、標準のインストールに含まれています)。
Hybrid API キーとローカルのポリシーファイルを組み合わせます。
英語の原文 -- 翻訳は技術レビュー待ちです
When you pass policy or policy_file explicitly to Client() alongside an api_key, your local policy governs enforcement and the hosted/dashboard bundle is IGNORED for that instance -- audit still ships to your dashboard.
この選択が分かるように、SDK は 1 回だけ警告を出力します(代わりに HybridModeError を発生させるには strict_hosted=True を渡します)。CONTROLZERO_LOCAL_OVERRIDE は、この明示的に引数を渡すケースには影響しません。影響するのは自動検出の場合のみです(api_key が設定されていて policy/policy_file を渡していないが、CONTROLZERO_POLICY_FILE または作業デ ィレクトリの controlzero.yaml/.yml/.json からローカルファイルが見つかった場合)。この場合はデフォルトでホスト型バンドルが優先され、CONTROLZERO_LOCAL_OVERRIDE=1 を設定すると、検出されたローカルファイルが優先されます。
from controlzero import Client
# Your local file governs enforcement; the hosted bundle is ignored.
client = Client(
api_key="cz_live_your_api_key_here",
policy_file="controlzero.yaml",
)
# The local file already governs enforcement; the API key only routes audit to the dashboard.
英語の原文 -- 翻訳は技術レビュー待ちです
Your local policy governs enforcement; the API key only routes audit to the dashboard.
SDK は、このインスタンスではダッシュボードのポリシーが無視されることを示す警告を 1 回だけ出力します(strict_hosted=True を設定した場合は HybridModeError を発生させます)。
Local API キー不要。
英語の原文 -- 翻訳は技術レビュー待ちです
No network calls.
完全オフライン。エアギャップ環境に対応します。
from controlzero import Client
# Inline policy -- no file needed
client = Client(policy={
"rules": [
{"allow": "database:query", "reason": "Reads are permitted"},
{"deny": "database:execute", "reason": "Writes are blocked"},
]
})
# Or from a file
client = Client(policy_file="controlzero.yaml")
英語の原文 -- 翻訳は技術レビュー待ちです
Every decision and its event-level coverage is written to ./controlzero.log, so “did not run” remains distinguishable from “ran and found nothing.”
設定
Hosted Hosted モード(推奨)
英語の原文 -- 翻訳は技術レビュー待ちです
Pass only your project API key. The SDK pulls the signed policy bundle from the dashboard at first call, verifies its signature, decrypts locally, and enforces every call against the dashboard policy. Audit entries ship to the remote trail automatically.
from controlzero import Client
client = Client(api_key="cz_live_your_api_key_here")
Local ローカルポリシーファイルを使う
from controlzero import Client
client = Client(policy_file="controlzero.yaml")
Hybrid Hybrid モード(API キー + ローカルポリシー)
from controlzero import Client
# Explicit policy_file + api_key: the local file governs enforcement,
# the hosted bundle is IGNORED, audit still ships remotely.
client = Client(api_key="cz_live_your_api_key_here", policy_file="controlzero.yaml")
インラインポリシー
from controlzero import Client
client = Client(policy={
"rules": [
{"allow": "database:query", "reason": "Reads are permitted"},
{"deny": "database:*", "reason": "All other database operations are blocked"},
]
})
database:query、database:execute、database:delete は従来のアクション名で、正式な database:read、database:write