How to Configure Gemini CLI Kubernetes Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a gemini cli kubernetes sandbox by giving the agent a scoped role in one namespace. You then bind that role to a dedicated identity so the agent cannot touch other workloads. Teams often run AI command line tools using their own local cluster files. Those local files usually hold broad admin rights across the whole cluster. When an AI tool uses broad rights, one bad command can break live apps. A proper sandbox limits where the agent can run commands and read logs. How to set up a g

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 gemini cli kubernetes sandbox by giving the agent a scoped role in one namespace. You then bind that role to a dedicated identity so the agent cannot touch other workloads. Teams often run AI command line tools using their own local cluster files. Those local files usually hold broad admin rights across the whole cluster. When an AI tool uses broad rights, one bad command can break live apps. A proper sandbox limits where the agent can run commands and read logs.

How to set up a gemini cli kubernetes sandbox with RBAC

First, create a dedicated namespace in your cluster just for the AI agent. This namespace acts as the boundary for the gemini cli kubernetes sandbox. Next, set up a Role inside that single namespace. In Kubernetes RBAC, a Role holds rules that represent a set of permissions. All RBAC rules are additive, and there are no deny rules. You must list only the exact resources the agent needs to do its job.

Start by allowing read actions on basic workloads like pods inside that namespace. If the agent must read pod logs, you have to grant the log subresource. Kubernetes RBAC writes subresources with a slash, such as the pod log subresource. If the agent needs to run commands inside a container, it needs the exec subresource. Granting pod read rights alone does not let the agent run container commands. You must add each subresource to the Role rules on purpose.

Avoid using a ClusterRoleBinding when you build this sandbox for your team. A ClusterRoleBinding grants permissions across the whole cluster, including all namespaces and nodes. Instead, use a RoleBinding within the sandbox namespace to link the agent identity. A RoleBinding grants permissions inside one specific namespace only. It can point to a Role in that same namespace or a shared ClusterRole. When you point the agent shell to this scoped identity, it stays inside the sandbox.

Why native RBAC roles leave a runtime gap for AI agents

Namespace Roles and RoleBindings solve the problem of where an agent can log in. They stop the AI tool from deleting workloads in other namespaces or reading cluster nodes. Still, native Kubernetes RBAC checks only the API verb and the target resource name. It decides who can start a command, not what the command does inside the pod.

Once you grant the exec subresource on pods, the agent can open a shell session. Kubernetes RBAC cannot inspect the shell commands that run inside that open session. An agent with exec rights can read local files or dump env vars inside the pod. It can also reach internal databases if the pod network allows those calls.

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 agent reads pod logs or queries a database pod. Pod logs and database tables often hold user emails, phone numbers, or card numbers. Native RBAC gives all-or-nothing read rights to the log stream or pod shell. It cannot mask sensitive fields like national IDs before the text reaches the AI model. It also cannot pause a risky shell command inside a pod to ask a human first.

Best practices for scoping agent identities in clusters

Never let the AI agent share the personal cluster file of a human engineer. Human engineers often hold cluster-wide rights to fix broken apps during an outage. Create a separate service account in the sandbox namespace for the AI tool instead. Bind that service account to a tight Role that covers only the sandbox workloads.

Keep the pod exec subresource off the Role unless the task truly requires shell commands. Most read-only debugging tasks only need pod status checks and the pod log subresource. If you must allow container commands, keep production secrets and live data out of that namespace. Treat every command the AI agent sends as untrusted input that needs strict limits.

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 sits inline as an open-source proxy, a sidecar for your Kubernetes API, without replacing RBAC. On every production call from an engineer or AI agent, hoop.dev decides to pass, mask, block, or hold it for human approval.

First, hoop.dev guardrails refuse banned methods, paths, or headers before they run or hold risky deletes for review. 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

Can I use a deny rule in Kubernetes RBAC to block Gemini CLI from secrets?

No, Kubernetes RBAC rules are purely additive and do not support deny rules. To block secret reads, leave the secrets resource out of every Role bound to the agent.

What happens if I bind the agent identity with a ClusterRoleBinding?

A ClusterRoleBinding gives the agent permissions across every namespace in the entire cluster. Always use a namespaced RoleBinding so the agent stays inside your designated sandbox namespace.

Does granting pod read access allow Gemini CLI to run commands in containers?

No, basic pod read permissions only let the agent view pod status and metadata. You must explicitly grant the pod exec subresource in the Role to allow container commands.

The query runs. The emails stay hidden.