How to Run AI Coding Agents on Kubernetes: Sandbox vs. Environment
A coding agent that can't run the application it changes is guessing. Anthropic's guide to building agents says it is "crucial for the agents to gain 'ground truth' from the environment at each step". So a platform team…
以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。
A coding agent that can't run the application it changes is guessing. Anthropic's guide to building agents says it is "crucial for the agents to gain 'ground truth' from the environment at each step". So a platform team that moves agents from laptops to Kubernetes has an additional question to answer: where does the agent deploy the application to test its changes?
Why Run AI Coding Agents on Kubernetes? covered why a cluster is a better place for agents than a laptop. This post answers that additional question, and argues that the agent sandbox is not the application environment: the application should not be deployed inside the sandbox where the agent runs.
The short version: run the agent in a light, unprivileged pod, run the application in a namespace per agent, and connect the two with remote execution, so the agent asks the cluster to build, deploy, and test its changes and reads the results.
They are two different things, and they tend to get mixed up:
The agent sandbox shares its name with Agent Sandbox, a Kubernetes SIG Apps project built to run it. The project adds a Sandbox resource with a stable identity, persistent storage, and lifecycle operations such as pausing, resuming, and scheduled deletion, plus templates and warm pools for fast startup. It doesn't isolate workloads by itself: it runs each sandbox on the runtime you choose, gVisor and Kata Containers included. Agent Sandbox manages where the agent runs, not where the application runs.
It is common to assume that the application environment runs inside the agent sandbox. It doesn't have to: the next sections compare running it inside the sandbox and running it outside, as a dedicated environment in the cluster.
The usual first design puts the agent sandbox and the application environment in the same place. Each agent gets a large pod with a Docker daemon inside, and the agent runs docker compose up to have something to test against.
The problems show up at scale, with many agents and many teams that have different requirements:
A fat agent sandbox is still a valid option, and the simplest one, when the application is small, when it isn't tied to Kubernetes, or when its tests run against mocks and don't need the real services.
The alternative is to split the two. The application environment lives outside the sandbox, in the cluster: the agent deploys it and exercises it through its endpoints and its tests. Each agent needs its own application environment, and Kubernetes already has the construct for that: the namespace. Resource names only have to be unique within a namespace, so many copies of the same application can run in one cluster, each with the same Deployment, Service, and PVC names, without colliding. Each agent gets an ephemeral namespace, created for its work and deleted when the work is done.
The sandbox keeps only what the agent needs to do its own job:
Everything else, the application itself included, moves to the application environment: builds, deployments, and tests run remotely in the cluster, compilation and unit tests included.
Remote execution connects the two layers: the agent changes code in the sandbox, and the build, the deployment, and the tests of that change run in the agent's namespace. There are two ways to get it:
Whatever the tool, images are built outside the sandbox, and the application is deployed from the definition that is already in the repository: the Helm chart or the Kubernetes manifests. That makes remote execution, in CI or on request, a checkpoint for the code the agent wrote: before any command runs, a guardrail can check the change for malicious code, like a script that sends credentials out of the cluster, in case untrusted input steered the agent.
With the two layers in place, an agent works the way a developer does: it writes a change, runs it, and looks at what happened. The orchestrator creates a namespace for the agent and starts the sandbox pod with the task, the repository, and credentials for that namespace only. The agent edits the code and asks for a build and a deployment of the application, from the definition in the repository. Then it verifies its output against a realistic copy of the application, not a simplified version of it: it runs the tests, exercises the endpoints, and troubleshoots with the Kubernetes API, the logs, and the metrics of its namespace. It repeats until the tests pass and the application behaves as expected, and then it opens a pull request. The verification is much more rigorous this way, and the quality of the agent's output is much higher.
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。