How to Configure AutoGen Kubernetes Sandbox
You set up an autogen kubernetes sandbox by creating a single namespace for agent pods. Then you bind a scoped role to the identity that runs the agent code. Many teams start by giving the agent runner broad cluster roles to move fast. That mistake lets generated code read cluster secrets or delete live workloads across namespaces. A safe setup locks the agent into one namespace with strict role rules. How an autogen kubernetes sandbox works with native roles AutoGen agents write scripts and
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 autogen kubernetes sandbox by creating a single namespace for agent pods. Then you bind a scoped role to the identity that runs the agent code. Many teams start by giving the agent runner broad cluster roles to move fast. That mistake lets generated code read cluster secrets or delete live workloads across namespaces. A safe setup locks the agent into one namespace with strict role rules.
How an autogen kubernetes sandbox works with native roles
AutoGen agents write scripts and run them to solve tasks for your team. Running this code on the host machine puts your main system at risk. A Kubernetes pod gives each agent task a clean place to run. You set up this flow with standard Kubernetes role-based rules.
In Kubernetes, a Role holds rules that grant permissions inside one specific namespace. A ClusterRole holds rules that can span the whole cluster and all nodes. Permissions in Kubernetes are only additive, which means there are no deny rules. You start with zero access and add only the exact actions the agent needs.
To lock down the sandbox, you create a Role inside the agent namespace. This Role allows the agent runner to create pods and read their status. Next, you create a RoleBinding in that same namespace to link the Role. Avoid using a ClusterRoleBinding here, because it grants permissions across the entire cluster.
Your agent runner also needs to send commands and read output from the pod. Kubernetes handles these actions through subresources like pod logs and pod exec endpoints. In your Role rules, you must list these subresources with a slash after pods. Without them, the agent runner can start a pod but cannot run code inside.
Network and resource limits for agent pods
Role rules control who can start pods, but pods also need runtime limits. An agent might write a bad loop that eats up all node memory. You can set CPU and memory limits on the namespace to stop this. These quotas keep a broken script from starving other apps on the same node.
You should also block the sandbox pod from talking to internal cluster services. By default, pods in Kubernetes can send traffic to other pods across namespaces. A network policy in the sandbox namespace stops the agent from reaching internal databases. You can allow only outbound traffic to approved web APIs if the task needs it.
Kubernetes RBAC + AI Sandbox Environments: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Pod security settings also matter when agents run untrusted code in a container. Make sure the sandbox pod runs as a non-root user with a read-only filesystem. Drop all extra Linux rights so a bad script cannot break out of the container. Delete the pod right after the agent task ends to clear any leftover files.
What native Kubernetes roles leave open
Native Kubernetes roles do a great job of controlling who can start pods. They also control which identity can open an exec channel into a running container. Once that channel opens, Still, Kubernetes RBAC stops checking what happens inside the session. The API server checks the initial request, not the commands sent inside the stream.
This gap matters when an agent or developer runs commands inside a sandbox pod. Role rules cannot tell a safe script apart from a command that dumps data. Also, if the pod holds database keys, any command inside can read raw tables. Native cluster logs show that an exec session started, not the full output returned. Teams often need deeper controls to inspect commands and mask fields like emails or card numbers.
Govern kubectl and API calls in flight
Identity providers and Kubernetes RBAC decide who logs into a cluster. They cannot redact keys inside returned JSON objects or hold a risky delete call for review. By design, hoop.dev runs as an open-source proxy, a sidecar for your Kubernetes API, checking requests and responses without replacing RBAC.
First, hoop.dev guardrails refuse banned methods, paths, or headers before they run. Next, hoop.dev data masking rewrites sensitive keys in returned Secret, ConfigMap, and log responses in memory, and writes each decision to the audit trail. Explore the repo on GitHub.
Frequently asked questions
Why should I use a RoleBinding instead of a ClusterRoleBinding for agent pods?
A RoleBinding keeps permissions inside a single namespace where the sandbox pods live. A ClusterRoleBinding gives access across the whole cluster, which risks live apps and nodes.
Why can my AutoGen runner create pods but fail to run code inside them?
Kubernetes treats pod exec and pod logs as separate subresources in the API. Your Role must include rules for those subresources with a slash, not just pods.
Can Kubernetes RBAC block specific shell commands inside the sandbox pod?
No, Kubernetes RBAC only checks if an identity is allowed to start an exec session. It does not inspect or block individual shell commands or scripts inside that session.
Related guides
In this post