Skip to content

All posts

KubernetesAI

Pod Security Admission levels for AI agent workloads

Ritesh Patel

Kubernetes: Pod Security Admission levels for AI agent workloads

Pod Security Admission applies one of three Pod Security Standards levels to each namespace: privileged, baseline or restricted. For AI agent pods, baseline blocks the known privilege escalations, and restricted adds container hardening that you set in the pod spec. Start with warn and audit on the agent namespace, fix what the warnings show, then enforce.

The three levels and what they mean for an agent pod

The Pod Security Standards define three levels. The Kubernetes docs describe them as cumulative, from the most permissive to the most restrictive. Privileged is unrestricted and allows known privilege escalations, so it does not suit a pod that runs tools chosen at runtime by a model. Baseline is minimally restrictive. Restricted follows current Pod hardening practice. The table below uses the Kubernetes v1.37 documentation, checked on 2026-11-15.

Level What the docs say What it blocks or requires for an agent pod Fit for agent pods
privileged Unrestricted, allows known privilege escalations Nothing Not for agent pods
baseline Prevents known escalations, allows the default Pod configuration Privileged containers, host namespaces, hostPath volumes, host ports, Unconfined seccomp, capabilities beyond the listed set Floor for any agent pod
restricted Follows current Pod hardening best practices Everything in baseline, plus allowed volume types only, no privilege escalation, non-root users, RuntimeDefault or Localhost seccomp, and dropping all capabilities Target for agent pods

Baseline is a reasonable floor for an agent that only runs code you wrote and reviewed. Restricted is the level to aim for when the agent executes commands it picked at runtime, because it limits the privileges a process in the container can gain. Neither level covers RBAC, NetworkPolicy or Secret access. An agent that passes restricted can still hold a token with more permissions than it needs.

Label the agent namespace in warn and audit mode

Each mode has its own level label and an optional version label. A namespace can set enforce, audit and warn to different levels. The docs say a dry run is helpful when you first evaluate a profile change, since it shows how existing pods would be treated. Sources: the Pod Security Standards, the Pod Security Admission page, and the namespace-label task.

  1. Set audit and warn to restricted on the agent namespace. Violations then appear in warnings and audit events, and pods still run.
kubectl label --overwrite ns my-agents \
  pod-security.kubernetes.io/audit=restricted \
  pod-security.kubernetes.io/warn=restricted
  1. Check existing pods with a server-side dry run of the enforce label. It reports what would fail among pods that already exist. The docs’ example applies it to all namespaces, so narrow it to your agent namespaces if the cluster is shared.
kubectl label --dry-run=server --overwrite ns --all \
  pod-security.kubernetes.io/enforce=restricted

The namespace dry run only tests pods that already exist. To check a new or scaled-to-zero Deployment, dry-run its manifest against a namespace that has the warn=restricted label from step 1. The warnings list each violation without creating anything.

kubectl apply --dry-run=server -f agent-deployment.yaml -n my-agents
  1. Fix each workload the warnings name. The docs say that when an enforce label is added or changed, the admission plugin tests each pod in the namespace, and violations come back as warnings.

  2. Enforce restricted and pin it to the version you tested against. The version label accepts a Kubernetes minor version or latest.

kubectl label --overwrite ns my-agents \
  pod-security.kubernetes.io/enforce=restricted \
  pod-security.kubernetes.io/enforce-version=v1.37

Restricted settings for an agent pod

A pod that meets restricted sets a few fields explicitly. The manifest below uses the field paths the standard lists. It writes scratch files to an emptyDir, which is one of the allowed volume types, and it requests no host access.

apiVersion: v1
kind: Pod
metadata:
  name: agent-runner
  namespace: my-agents
spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 10001
    seccompProfile:
      type: RuntimeDefault
  containers:
  - name: agent
    image: ghcr.io/example/agent:1.0.0
    securityContext:
      allowPrivilegeEscalation: false
      capabilities:
        drop:
        - ALL
    volumeMounts:
    - name: workdir
      mountPath: /work
  volumes:
  - name: workdir
    emptyDir: {}

The image name is illustrative. Replace ghcr.io/example/agent:1.0.0 with your own agent image, and confirm it runs as UID 10001 without needing root-only file access.

Three details catch people out. The only allowed value for allowPrivilegeEscalation is false, so leaving it out fails the check. Container-level runAsNonRoot and seccompProfile may be left unset when the pod-level field is set correctly, which the example relies on. And the restricted check covers every container and init container. The standard says that if any listed container fails, the entire pod fails validation, so one sidecar with the wrong setting blocks the whole agent.

Fine print that changes the outcome

  • Enforce applies to pods, not workloads. A Deployment whose template breaks the level is still accepted. The pods its controller creates are what get rejected. A namespace dry run cannot see a Deployment with no pods yet, so dry-run the workload manifest before you roll out: kubectl apply --dry-run=server -f agent-deployment.yaml -n my-agents.
  • Exemptions skip all three modes. Exemptions match usernames, RuntimeClassNames or namespaces. The docs advise against exempting controller service accounts, because that exempts anyone who can create the workload.
  • Warn and audit never block. Warn shows a warning to the user, and audit writes an annotation to the audit event. A pod that violates either level still gets created.
  • Pin restricted on mixed-version clusters. The docs say kubelets before v1.24 do not enforce the pod OS field. If some nodes run an older version, pin restricted to a version before v1.25.

Check the level before you ship an agent

  1. Does the pod need hostNetwork, hostPID, hostIPC or privileged? Baseline forbids all of them. Move that work into a separate workload that runs in a namespace at a level that allows it, or redesign it.
  2. Does it mount a hostPath volume? Both levels reject it. Restricted allows only configMap, csi, downwardAPI, emptyDir, ephemeral, persistentVolumeClaim, projected and secret, so use one of those.
  3. Does it run as UID 0 or add capabilities? Restricted permits no added capabilities except NET_BIND_SERVICE, and it requires a non-zero runAsUser when one is set.
  4. Does it set seccomp to Unconfined? Both levels forbid it. Use RuntimeDefault or Localhost.
  5. Does it need more API access than its own namespace? The levels cannot answer that. Review the service account and RBAC separately.

Enforcing this with Pod Security Admission

Pod Security Admission is an admission controller, so you do not need another component to enforce the three levels. Apply the labels from the steps above to every agent namespace, and keep them in the namespace manifest so they survive a rebuild. Keep the warn and audit labels when you enforce, so new violations stay visible.

The Pod Security Standards page also says other enforcement tools are being developed in the Kubernetes ecosystem, and it names Kyverno among them. If you need a control these three levels do not express, the Kyverno OSS page is the product page for that option. For the identity, network and sandbox controls around the same agent pods, read the AI agent threat model for Kubernetes, how to sandbox AI agents on Kubernetes and governing AI agents in Kubernetes.

Sources

Frequently asked questions

Should an AI agent pod run at baseline or restricted?

Aim for restricted. Baseline is the floor: it blocks privileged containers, host namespaces, hostPath volumes and Unconfined seccomp profiles. Restricted adds non-root users, no privilege escalation, a RuntimeDefault or Localhost seccomp profile, and dropping all capabilities except NET_BIND_SERVICE. Use baseline only for an agent that needs a setting restricted forbids, and record that exception in the namespace.

Does Pod Security Admission reject a Deployment that breaks the level?

Not at the Deployment object. The Pod Security docs say enforce mode is not applied to workload resources, only to the resulting pod objects. The Deployment is accepted, and the pods its controller tries to create are rejected. Dry-run the workload manifest with `kubectl apply --dry-run=server` and read the warnings before you enforce, so the failing template turns up before a rollout does.

Does restricted stop an agent from reading Secrets or calling the Kubernetes API?

No. The Pod Security Standards check security context fields and volume types. They do not cover RBAC, service account token settings or NetworkPolicy. An agent that passes restricted can still hold a service account with broad permissions. Limit its RBAC and egress separately, and check each path in an agent threat model.

Can I run warn and audit before enforce without breaking deployments?

Yes. Warn returns a user-facing warning, and audit adds an annotation to the audit log event. Both allow the pod, so neither blocks a deployment. Leave them on while you fix workloads, and switch enforce on once the namespace no longer shows violations you need to fix.

Ritesh Patel, Founder & VP Product, Nirmata

Ritesh Patel is a founder of Nirmata and leads its products. He writes about governing AI coding agents, MCP security and Kubernetes policy as code.

LinkedIn

Govern AI agents with AIControlsControl what AI agents do, and prove it.
Share

Stay up-to-date with the latest in AI, governance, and infrastructure

Subscribe to our free monthly newsletter to get industry news, DevOps tips, and articles right to your inbox on Kyverno, containerization, Kubernetes deployment & management and more.