InfoQ published "Securing Autonomous AI Agents on Kubernetes: Trust Boundaries, Secrets, and Observability." It outlines architectural guidance for safeguarding autonomous AI agents running on Kubernetes across three axes: trust boundaries, secrets, and observability.
In custom development, cases where teams deploy "AI agents that autonomously modify and deploy code during nightly batch runs" to client production K8s clusters are surging. This presents a risk profile distinct from traditional "stateless web applications" and belongs to a domain that cannot be secured as a mere extension of conventional K8s operations. In this article, we outline standard designs when deploying autonomous AI agents to client K8s clusters in custom development.
Why conventional K8s operations are insufficient
We summarize the fundamental differences between traditional web applications and autonomous AI agents.
| Dimension | Traditional web apps | Autonomous AI agents |
|---|---|---|
| Determinism of behavior | High (same input → same output) | Low (behavior can change even with identical input) |
| Scope of external calls | Fixed at design time | Determined dynamically at runtime |
| Required privileges | Deducible from functionality | Uncertain until execution |
| Behavior on failure | Returns error and terminates | Retries, explores alternative paths, self-corrects |
| Ease of auditing | Traceable through logs | Unclear why a specific decision was made |
In particular, the characteristic where "the scope of external calls is determined dynamically at runtime" clashes with K8s designs using NetworkPolicy to "open only authorized egress," often forcing a choice between opening excessively or closing excessively and bottlenecking the agent.
Designing trust boundaries: The 3-layer model
Here is the 3-layer trust boundary model synthesizing the InfoQ article and our own implementation experience.
┌─────────────────────────────────────────────────┐
│ Layer 3: Outer Boundary(顧客環境境界) │
│ - VPC / Cluster Egress Gateway │
│ - NetworkPolicy で外部 LLM API のみ許可 │
└─────────────────────────────────────────────────┘
↑
┌─────────────────────────────────────────────────┐
│ Layer 2: Tenant Boundary(テナント境界) │
│ - Namespace ごとの ResourceQuota / LimitRange │
│ - PodSecurityAdmission(restricted) │
│ - サービスアカウント・RBAC の最小権限化 │
└─────────────────────────────────────────────────┘
↑
┌─────────────────────────────────────────────────┐
│ Layer 1: Agent Boundary(エージェント境界) │
│ - gVisor / Kata Containers(カーネル隔離) │
│ - read-only root filesystem │
│ - capabilities: drop ALL │
│ - 実行ツールは sidecar 経由で呼ぶ │
└─────────────────────────────────────────────────┘
Layer 1 (Agent Boundary) is the most critical. Because autonomous AI agents carry the risk of "performing unintended actions when fed crafted external inputs," you must isolate the agent Pod itself using technologies like gVisor and separate tool execution via sidecar containers. Even if the agent Pod is compromised, impact on the host OS and other tenants is minimized.
This aligns with the "least privilege for agents" philosophy covered in HashiCorp Vault 2.0 and Identity Federation; ensuring Vault's short-lived secret distribution is contained entirely within Layer 1 represents the custom development standard.
Secret distribution: Eliminating "lingering secrets"
The easiest trap to fall into in custom development environments is how secrets are supplied to agents.
Anti-Pattern 1: Static API keys in environment variables
env:
- name: OPENAI_API_KEY
value: "sk-..." # ← 絶対やらない
The instant an agent Pod is compromised, the API key is exfiltrated, leading to a complete takeover of the client's account.
Anti-Pattern 2: Secrets in ConfigMaps
kind: ConfigMap # ← Secret じゃない
data:
api-key: "sk-..."
ConfigMaps easily leak into audit logs and result in secrets being retained long-term via backups, so avoid this approach.
Recommended Pattern: Dynamic retrieval of short-lived tokens
[Agent Pod 起動時]
↓
[Vault / Workload Identity 経由で OIDC トークン取得]
↓
[OIDC トークンを LLM プロバイダの "STS 風" エンドポイントに提示]
↓
[15 分有効の API キーを発行]
↓
[15 分ごとに自動ローテーション、ファイルにも残さない]
Because no static secrets reside within the agent Pod under this pattern, the direct attack chain leading from Pod compromise to secret exfiltration is severed.
| Secret type | Distribution method | Lifetime |
|---|---|---|
| LLM API key | OIDC + STS-style endpoint | 15 min |
| DB connection info | Vault dynamic secrets | 1 hour |
| Cloud IAM | Workload Identity | Per request |
| Client API key | Vault + Transit | Per use case |
Sandboxing tool execution
Run tools invoked by autonomous AI agents (code execution, shells, file operations) in separate Pods or containers distinct from the main agent.
[Agent Pod]
├ agent コンテナ(LLM 推論・判断)
├ tool-executor サイドカー(ツール実行ゲートウェイ)
└ observability サイドカー(ログ・トレース送出)
[Tool Pod(ジョブ単位で起動)]
├ shell-runner Pod(gVisor)
├ python-runner Pod(gVisor)
└ db-query-runner Pod(最小権限 SA)
Make Tool Pods disposable per job, completely isolating the filesystem and network. This ensures that even if an agent generates a malicious shell command, the damage remains contained inside the Tool Pod.
This shares the direction of the "isolation of destructive operations" discussed in Production DB Deletion Guardrails for AI Agents; architecting so that the AI itself lacks direct database connection credentials is the deciding factor.
Observability: Preserving the "why" behind actions
Observability for autonomous AI agents is structured across four axes, supplementing standard metrics, logs, and traces with "decision logs."
| Axis | Details | Storage destination |
|---|---|---|
| Metrics | Request counts, token consumption, tool invocation counts | Prometheus |
| Logs | Standard application logs | Loki / CloudWatch |
| Traces | Chain of LLM call → tool invocations | Tempo / Jaeger |
| Decision logs | Full prompt text, full output text, selected execution paths | Long-term storage in S3 + encryption |
Decision logs are essential during an incident to reconstruct "why the AI chose this specific action." By retaining all prompts and outputs long-term, investigations can withstand post-mortems conducted three months later.
However, because decision logs contain client data, designing storage encryption, access control, and retention periods is mandatory.
Pod admission policies via OPA / Kyverno
When agents launch new Pods (parallel jobs, Tool Pods, etc.), enforce launch authorization rules via OPA Gatekeeper / Kyverno.
| Policy | Details |
|---|---|
| Allowed image registries only | Deny registries other than the customer's container registry |
| Enforce privileged: false | Completely prohibit launching privileged Pods |
| Enforce read-only root filesystem | Deny Pods with a writable rootfs |
| Restrict to specific namespaces | Agents can launch Pods only within designated namespaces |
| Enforce imagePullPolicy: Always | Prevent cache attacks using outdated images |
The audit log entry itself stating that "an agent attempted to create a Pod rejected by OPA" can be used for early detection of anomalous agent behavior.
Five pitfalls easy to stumble into in custom development
Pitfall 1: The customer cannot distinguish the "AI namespace"
Co-locating AI agents within existing application namespaces makes troubleshooting and isolation during incidents difficult. Clearly specify "dedicated AI namespace + dedicated node pool" in contractual terms.
Pitfall 2: GPU node cost explosion
Running agents without controlling their degree of parallelism causes GPU node autoscaling costs to balloon to 3–5 times what was expected. Enforce a Pod-level parallelism limit via OPA.
Pitfall 3: Behavior during LLM provider outages
During OpenAI or Anthropic outages, agents fall into retry loops, causing logs to expand exponentially. Build in a circuit breaker + human escalation during incidents by default.
Pitfall 4: Decision log volume explosion
Retaining all prompts can result in logs reaching several terabytes per month. Establish a policy of "differentiating retention periods by importance" during the design phase.
Pitfall 5: Failed operational handover on the customer side
All too often, implementation finishes but the customer cannot operate it, leading to a state where "our company has to keep monitoring everything." Always include runbooks + Day-1 to Day-90 operational training in deliverables. This aligns with the philosophy of "delivering in a form the customer can operate" covered in contracted maintenance for Vercel Open Agents.
Summary — Elevating the quality of "running AI on K8s"
While use cases for running autonomous AI agents on K8s are surging, many implementations lack standardized trust boundaries, secret distribution, and observability, making the risk that an incident at a single customer could dampen industry momentum for AI adoption increasingly real.
We package the construction and maintenance of K8s autonomous AI agent platforms following the standard architecture in this article into three tiers: Starter, Standard, and Enterprise. If you want to safely run AI agents on your internal K8s or redesign an existing agent platform, please feel free to reach out via our contact form.








