How to Configure CrewAI Kubernetes Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a crewai kubernetes sandbox by binding agent tasks to a single namespace. You also restrict what cluster actions the agent role can perform. Engineering teams often deploy agent tools inside shared clusters to run code and check system state. When those agent roles get wide permissions, a bad prompt can alter workloads across the cluster. How a crewai kubernetes sandbox uses role rules A safe agent setup starts with strict Kubernetes role-based access control. In Kubernetes, a Role

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 a crewai kubernetes sandbox by binding agent tasks to a single namespace. You also restrict what cluster actions the agent role can perform. Engineering teams often deploy agent tools inside shared clusters to run code and check system state. When those agent roles get wide permissions, a bad prompt can alter workloads across the cluster.

How a crewai kubernetes sandbox uses role rules

A safe agent setup starts with strict Kubernetes role-based access control. In Kubernetes, a Role holds rules that represent a set of permissions in one namespace. A ClusterRole is not namespaced and can cover resources across all namespaces. Because permissions are additive and have no deny rules, you must start with zero permissions. You then grant only what the agent task needs inside its dedicated sandbox namespace.

To bind the agent to that single namespace, you create a RoleBinding. A RoleBinding grants permissions within a specific namespace by referencing a Role or a ClusterRole. You should avoid using a ClusterRoleBinding for an agent sandbox. A ClusterRoleBinding grants access across the whole cluster, which breaks namespace isolation. When an agent runs tasks, it uses a service account tied to that local RoleBinding.

You also need to control how the agent interacts with running pods. Kubernetes RBAC refers to resources by the same name that appears in the API URL. Some APIs involve a subresource, such as a pod log or an exec call. In RBAC, you write the subresource with a slash, like pods/log or pods/exec. If your agent only needs to read output, you grant the log subresource alone. You leave out the exec subresource so the agent cannot run arbitrary shell commands inside pods.

What native cluster roles solve and what they miss

Native cluster roles and bindings solve the first layer of sandbox security. They control which service account can call specific Kubernetes API endpoints in a namespace. If an agent tries to delete a node or read another namespace, the API server blocks it. This boundary keeps an agent task from escaping its assigned namespace through the cluster API.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Still, cluster roles only check who logs in and which API resource they call. They do not inspect what happens inside an allowed session or database call. Once an agent has permission to run pod commands or query a store, RBAC steps aside. If you allow the exec subresource on a pod, the role cannot inspect the shell commands. Also, the resourceNames rule on create applies only to top-level resources, not to subresources. That makes it hard to lock down specific exec targets using native RBAC alone.

The same gap appears when a sandboxed agent queries an internal database. Cluster roles do not read SQL statements or filter out sensitive fields in query results. If a table holds customer emails, phone numbers, or card numbers, the query returns them raw. Native RBAC also cannot pause a risky command to ask a human for approval first. Teams need controls that inspect each command and mask matched fields like national IDs in results.

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 a CrewAI sandbox use a RoleBinding instead of a ClusterRoleBinding?

A RoleBinding keeps permissions inside one namespace. A ClusterRoleBinding grants permissions across the entire cluster, which lets an agent reach outside its sandbox.

How do you let a sandboxed agent read pod logs without running shell commands?

Grant permission for the pods/log subresource in your Role rule. Leave out the pods/exec subresource so the agent cannot open a shell inside any pod.

Can Kubernetes RBAC block dangerous SQL queries or mask data inside a sandbox?

No, Kubernetes RBAC only checks calls to the cluster API server. It does not inspect database queries, block destructive statements, or rewrite emails and card numbers in results.

The query runs. The emails stay hidden.