Running Kubernetes AI agents looks like a natural fit: the platform already runs most containerized services at scale. But an agent session behaves differently from a microservice, and four of those differences strain the way Kubernetes allocates compute, isolates code, filters traffic and assigns identity.
Picture a coding agent editing a codebase. It waits minutes for a model reply, writes a script, runs it, calls a remote API and pushes a change for someone. Each step asks something different of the infrastructure.
Idle time wastes a Pod per session
Agent sessions stay open long after the local work is done. The agent may be waiting for a person to approve an edit, for a model to respond or for a remote test run to finish. An interactive agent can sit idle for up to 95% of a session, though the share varies by application.
One agent might work in short bursts all day. Another might edit a repository for a few minutes and then wait hours for a review. Give each session a dedicated Pod and memory stays reserved for thousands of agents when only a handful have anything to do.
Agent Substrate, a runtime built for this problem, separates the life of a session from the life of its worker Pod. When the application decides a session is safe to pause, Substrate snapshots it and frees the worker for another agent. The session can resume later on a different worker. It works like CPU time-sharing, applied to whole agent environments.
Agents choose their own code at runtime
A conventional microservice ships code that developers wrote, with execution paths they defined. An agent picks its next action while it runs. With a shell tool, it can write a Python script that rewrites files in the repo and run it moments later.
That script has whatever access the environment grants. It can change files, start processes or probe the host and neighboring workloads. The isolation boundary has to hold no matter what the model decides to execute.
For Kubernetes AI agents, the fix is a sandbox per active agent. Substrate gives each one its own gVisor or microVM sandbox. Several agents can take turns on one worker Pod, and each keeps a separate execution boundary.
Outbound traffic is the new risk
Code can stay inside its sandbox and still ship proprietary source to an outside server. The coding agent in this example needs the repository and one approved model endpoint. Nothing justifies uploading files to some random address. Since the model picks the requests, policing outbound traffic becomes as important as guarding what comes in.
Even the approved endpoint can receive a prompt that contains personal data or private code. The destination says where a request is going. It says little about what the agent is sending.
Substrate mediates traffic in both directions and applies policy to DNS lookups. The egress gateway checks every destination and can add an API key or token to an approved call, which keeps the credential outside the sandbox. Inspecting the payload needs a further policy, and the API on the other end still decides whether to allow the action.
Who is actually acting?
Say two users each ask the same coding agent to push a commit. One has write access to the repository and the other can only read it. The repository needs a way to tell the requests apart.
A microservice usually has a single workload identity. For agents, the API also needs to know which session is acting, whose permissions it is borrowing and for how long. That identity has to follow the session when it moves to another Pod. If a push goes wrong, you should be able to trace it to the session and the user who authorized it, and that trail can span more than one token.
Each agent gets a short-lived SPIFFE certificate from Substrate, and an agent JWT can be minted when needed. The application verifies the user and ties that person’s permissions to the session. Passing that authority to a backend means integrating with the relevant identity systems. OAuth 2.0 Token Exchange is one route to a delegated token with narrow permissions and a short lifetime. Substrate’s own on-behalf-of flows remain in design.
How the pieces stack up
Agent Substrate is the generic runtime underneath. Its vocabulary is actors, sandboxes and snapshots. Prompts, models and tools are outside its view.
kagent sits on top as the agent layer. You create an agent in kagent and talk to it there, and kagent runs it on Substrate without exposing actors, worker Pods or snapshots. agentgateway sits on the outbound path, between an agent and the models, tools and APIs it reaches.
Until the on-behalf-of flows are finished, teams running Kubernetes AI agents will need to wire token exchange into their own identity setup. The same goes for payload filtering on egress. Expect more detail on how the three layers fit together as the projects mature.
Source: generativeprogrammer.com