How to Configure OpenAI Agents SDK Kubernetes Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up an openai agents sdk kubernetes sandbox by binding a strict role to one namespace. Then you wire your agent tools to run tasks inside isolated pods in that space. Engineering teams often build this setup so AI agents can test code or check cluster state. Still, many teams start by giving the agent a broad role across the whole cluster. When an agent holds wide permissions, one bad prompt can delete pods or leak secrets. A safe setup keeps the agent inside a tight boundary from the ver

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up an openai agents sdk kubernetes sandbox by binding a strict role to one namespace. Then you wire your agent tools to run tasks inside isolated pods in that space. Engineering teams often build this setup so AI agents can test code or check cluster state. Still, many teams start by giving the agent a broad role across the whole cluster. When an agent holds wide permissions, one bad prompt can delete pods or leak secrets. A safe setup keeps the agent inside a tight boundary from the very first run.

How an openai agents sdk kubernetes sandbox works with native roles

In the OpenAI Agents SDK, an agent uses custom Python tools to take actions. You write a tool function that calls the cluster API to create or run a pod. The model picks this tool when it needs to run a script or check logs. Your tool code sends the request to the cluster API server using a service account token.

Kubernetes role-based rules control what that service account token can do inside the cluster. In this system, permissions are purely additive, which means there are no deny rules. You define a Role to set permissions inside one specific namespace for the sandbox. By contrast, a ClusterRole covers the whole cluster and can touch nodes or all namespaces. For an agent sandbox, you should use a single namespace Role and a RoleBinding. That binding links the agent service account to the allowed actions in that one namespace.

You also need to watch how the agent interacts with pod subresources in the API. Reading pod logs or running commands inside a pod uses subresources like pod log or exec paths. If you grant the exec subresource, the agent can run shell commands inside running containers. Your role rules must list the exact resources and subresources the agent tool needs.

What native cluster roles solve and what they leave open

Native roles and bindings do a good job of keeping an agent inside one namespace. They stop the agent from touching production apps that live in other parts of the cluster. They also block the agent from changing cluster nodes or reading secrets in other spaces. This gives your platform team a strong first wall against broad cluster damage.

Still, native role checks only decide who can call an API endpoint at login time. Once a role grants pod exec permissions, the cluster API does not inspect the shell commands. An agent with exec permissions can run any command inside that sandbox container. It can pull sensitive files, scan the local network, or print raw data to the logs.

Kubernetes RBAC + AI Sandbox Environments: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

The same problem happens when the sandbox pod reaches out to internal data stores. If the pod holds database keys, the agent can query tables and return customer emails. It might also pull phone numbers, card numbers, or national IDs into the model context. Native cluster roles cannot rewrite matched fields in results or pause a risky command in flight. Teams also struggle to link a raw cluster API call back to the specific agent run. To run agents safely, you need controls that inspect commands and data during each step.

Practical steps to tighten your agent sandbox

Start by creating a dedicated namespace just for your agent workloads and test pods. Never bind your agent service account to a ClusterRoleBinding if a single namespace works. Keep the Role rules minimal by listing only the verbs and resources the tool requires. Remove exec access on pods unless the agent must run live commands in a container.

Next, limit what the sandbox pod itself can do once it starts running code. Drop all extra Linux capabilities on the container and run the process as a non-root user. Mount the root file system as read-only so the agent cannot alter system binaries. Do not mount the default service account token inside the sandbox pod unless needed. This stops code inside the pod from calling the cluster API on its own. Finally, clean up finished sandbox pods right after the agent completes its task.

Add request guardrails and response masking beside Kubernetes

Cluster roles and service accounts govern who reaches the Kubernetes API. Still, a broad role or agent can delete workloads or print sensitive values from ConfigMaps and logs. In practice, hoop.dev runs beside the API server as a sidecar for your Kubernetes API and checks every request and response alongside RBAC.

With hoop.dev Kubernetes controls, guardrails can allow listing Secret names while refusing reads of Secret data before execution. Data masking redacts matched keys in returned JSON responses and log streams in memory. Furthermore, hoop.dev holds SOC 2 Type II and is MIT licensed on GitHub.

Frequently asked questions

Why should an agent use a Role instead of a ClusterRole?

A Role keeps the agent locked inside one single namespace for all its work. A ClusterRole can span all namespaces and expose cluster nodes or other apps to risk.

Can Kubernetes RBAC block specific shell commands inside a sandbox pod?

No, native RBAC only checks if the account can call the pod exec API subresource. It does not read or filter the actual shell commands sent inside that stream.

How do I stop sandbox pods from calling the cluster API?

Turn off automatic service account token mounting in the pod spec for your sandbox workloads. Without a mounted token, processes inside the container cannot log in to the cluster API server.

The query runs. The emails stay hidden.