---
title: What would an AI agent's kubectl write break? Check before it runs
url: https://zhukovskyi.space/blog/ai-agent-kubectl-what-would-break/
description: An agent's kubectl patch looks harmless until you know which pods sit behind the Service. kube-belay dry-runs each write on the API server, tells you what it would break and holds it until you say yes.
---

[← all posts](/blog/)

# What would your AI agent's kubectl command break?

2026-12-02 · [engineering](/blog/engineering/) · #kube-belay · Andrii Zhukovskyi

**In short**

[kube-belay](/tools/kube-belay/) is a local proxy between an AI agent and your cluster. It replays each write with `dryRun=All`, tells you what would follow and waits for your keypress. It does not stop an agent that wants to get around it.

Claude Code, Cursor and the Kubernetes MCP servers are good at reading a cluster. Sooner or later you want them to write too: roll out a fix in staging, clean up a namespace. A read-only kubeconfig rules that out, and approving each command by eye doesn't help much.

## The command doesn't tell you much

Here's a write an agent might send while "fixing the rollout":

```
kubectl patch service web -n shop -p '{"spec":{"selector":{"app":"web-v2"}}}'
```

It reads fine. But if no pods are labelled `app=web-v2` yet, traffic to `web` stops the moment the patch lands. Other writes that hurt work the same way:

| The command | What it depends on |
|---|---|
| `kubectl delete pvc data-0` | The volume's reclaim policy: with `Delete`, the disk and its data go |
| `kubectl delete namespace shop` | What is inside it, and which of it holds state |
| `kubectl apply -f rbac.yaml` | Whether a binding points at `cluster-admin` or a role gains `escalate` |

A guard that pattern-matches the command line would catch `delete namespace` here and miss the rest. It also never sees writes that aren't shell commands, like a client-go program or an MCP server call.

## What a dry run leaves out

Any write to Kubernetes can be sent with `dryRun=All`. The API server runs defaulting, validation and admission, then returns the object it would store without storing it.

That gives you the new selector, `app=web-v2`. It doesn't tell you that 3 pods matched the old one and none match the new one. For that you have to read the live cluster around the object.

## How kube-belay does it

![kube-belay on your machine between the AI agent and the Kubernetes API server: the agent has only a session kubeconfig, kube-belay keeps your real credentials, reads pass, writes are dry-run and wait for your yes](/img/kube-belay/where-it-sits.svg)

kube-belay is a local HTTPS proxy. It keeps your real credentials and gives the agent a session kubeconfig whose token works only against kube-belay. Reads pass through. For every write it:

1. replays the agent's exact bytes with `dryRun=All` and, for a delete, works out what goes with it;
2. runs 37 rules written in code (no model) and lets a policy file decide allow, ask or deny;

3. on ask, shows a prompt in your terminal and waits for a key;
4. on yes, dry-runs again and forwards the same bytes; on no, returns a 403 with your note.

The prompt for the Service patch above, from a real run:

```
PATCH  service/web in shop
  Dry run on the API server: accepted (dryRun=All, nothing changed yet).
  What changes:
    spec.selector.app: web → web-v2
  What follows (kube-belay's reading, not the API server's):
    ▲ KB113 Service web changes: selector app=web → app=web-v2; pods behind it: 3 → 0, so traffic to it stops
  #5 patch service/web in shop. Approve? [y] yes  [n] no  [m] no, with a note  [d] details
```

For `kubectl delete namespace shop` you get the objects counted by kind, the PVC whose volume has reclaim policy `Delete`, and the number of pods that stop. For a critical finding like that you have to type the word `yes`.

## Will you end up pressing y all day?

That's the failure to avoid, so it asks as little as it can.

- Reads never ask, except for a single Secret's values.
- A write whose dry run changes nothing passes. So do the agent's own dry runs.

- Install, upgrade and uninstall of a default Helm chart take 11 prompts in total, down from 21 in the first version.
- `kube-belay serve --observe` lets everything through and reports what it would have asked. Run it for a day first.

If you don't answer within 100 seconds, the agent gets a 403 saying the request is waiting for you. Your yes later lets that exact request through once, within 15 minutes.

## What it doesn't do

kube-belay doesn't stop an agent that wants to get around it. One running as your OS user can read your other kubeconfigs, mint credentials with `aws` or `gcloud`, or just stop the proxy. `kube-belay doctor` lists the easy ways around it on your machine. For a real boundary, run the agent as a separate user or in a container or VM, with only kube-belay's kubeconfig.

It doesn't replace RBAC or an admission controller either: it only sees traffic sent through it, from one machine. Other tools in this area are [listed in the repository](https://github.com/andronaft/kube-belay/blob/main/docs/related-work.md).

## Try it

One command against your own cluster, with no agent and nothing changed:

```
kube-belay preview -- kubectl delete namespace shop
```

The full loop, on a throwaway local API server (needs Go 1.26+, downloads about 100 MB once):

```
git clone https://github.com/andronaft/kube-belay && cd kube-belay
make try     # starts a demo cluster and serve; a second terminal plays the agent
```

v0.3.0 is a pre-release for macOS and Linux. It's tested against a real kube-apiserver with kubectl, Helm 4.3 and kind, with Claude Code as the agent. It hasn't run on EKS, GKE or AKS. If you try it there, or a prompt tells you nothing new, open an issue.

Source: [github.com/andronaft/kube-belay](https://github.com/andronaft/kube-belay) (Apache-2.0) · Product page: [kube-belay](/tools/kube-belay/) · For manifests before they reach the cluster: [k8s-guardian](/blog/kube-tooling-why/).

About the tool: [kube-belay, see what your AI agent's kubectl write would break before it runs](/tools/kube-belay/).

© 2026 Andrii Zhukovskyi · apps and free tools published as [Dre Dev](/about/)
