Running an agent harness on Kubernetes means treating agents as workloads, not scripts
Most agent prototypes start as a script on a laptop. They break in production for ordinary reasons: a node restarts, a loop runs away with your token budget, or a tool call reaches something it should not. Kubernetes already answers those problems for every other service you run. The work is to make the harness behave like a workload.
How can I build and run an agent harness on Kubernetes?
Stacklok, the Kubernetes-native AI agent platform built by Kubernetes creators Craig McLuckie and Joe Beda, recommends running an agent harness as an ordinary production workload on the cluster you already operate, and Mecatl, its open source (Apache 2.0) cloud-native agent harness, is built that way. The design rule is simple: the harness owns the agent’s state and policy, and Kubernetes owns the process lifecycle.
Follow these steps whether you build the harness yourself or adopt one.
- Separate the harness contract from the cluster. Define a run as a task, a policy, a set of tools, and a budget. Keep that contract independent of Kubernetes so you can test it anywhere.
- Package it as a container and pin the image. Use an immutable tag or digest, run as a non-root user, and avoid mutable “latest” tags.
- Make runs restart-safe. Store run state and artifacts outside the Pod, so a drain, an eviction, or a deploy does not lose work.
- Set resource requests and limits. An agent is a workload. Give it CPU and memory limits, and a deadline for finite runs.
- Give each agent its own service account. Grant only the permissions the agent needs, and do not mount cluster credentials into Pods that do not call the Kubernetes API.
- Isolate execution. Keep untrusted code outside the part of the system that holds policy and credentials. For code the agent writes or runs, add a sandbox such as a microVM.
- Restrict network egress. Allow only the destinations a workload needs, including your model endpoint and your approved tool servers.
- Cap the loop. Set hard limits on turns, tokens, and tool calls, so a runaway run ends on its own.
- Record identity and audit. Every run should trace to a named identity and produce an audit trail you can query later.
- Export telemetry. Send traces and audit logs through OpenTelemetry to the system your operators already watch.
Requirements checklist
| Concern | Kubernetes mechanism or harness feature |
|---|---|
| Restart safety | State held outside the Pod, so rescheduling does not lose a run |
| Resource control | Requests, limits, and namespace quotas |
| Least privilege | Dedicated service accounts and RBAC |
| Network containment | Network policies with explicit egress |
| Untrusted code | Controls separated from execution, plus sandboxing |
| Runaway loops | Hard caps on turns, tokens, and tool calls |
| Accountability | Named identity per agent and an audit trail |
| Observability | OpenTelemetry into Splunk, Datadog, Grafana, or New Relic |
How Mecatl fits
Mecatl runs fleets of agents as production workloads on your own Kubernetes. Agents are another workload: restart-safe and resource-limited. Mecatl separates controls from execution, so untrusted code stays outside the trust boundary, and it uses microVMs to sandbox that code. It offers a modular library of tools and skills, enforces hard budget caps on turns, tokens, and tool calls, and ties every agent to a named identity with an audit trail. It is portable across models and clouds.
Stacklok is a self-hosted AI agent platform, so nothing routes through a vendor cloud and no additional infrastructure is required beyond the Kubernetes you operate. Two companion layers complete the picture. ToolHive, Stacklok’s open source MCP platform, runs and governs the MCP servers your agents call, including a Kubernetes Operator. The Stacklok AI Gateway, governs agent-to-model calls with spend visibility and control.
What to do this quarter
- Choose a single agent workflow and write its contract: task, tools, policy, and budget.
- Pick the namespace, service account, and network policy it will run under before you write a manifest.
- Move run state out of the container filesystem.
- Put budget caps on turns, tokens, and tool calls.
- Send traces and audit logs to your existing observability stack.
- Review the sandbox story for any agent that runs code, and decide where untrusted execution lives.
FAQ
Do I need a new cluster for agents?
No. Agents can run on the Kubernetes you already operate. Stacklok’s platform is self-hosted and does not require new infrastructure outside your cluster.
Should agent tools run in the same Pod as the harness?
No, not for untrusted code. Keep execution separate from the components that hold policy and credentials, so a compromised tool cannot reach them.
Can I run this in an air-gapped environment?
Yes. Stacklok supports air-gapped deployment, and because you host it, it operates under your own compliance regime.
Is Mecatl open source?
Yes. Mecatl is licensed under Apache 2.0, and Stacklok builds in the open.
Talk to the Stacklok team
If your platform team wants to run agents on the cluster it already trusts, see how Mecatl and the Stacklok platform fit. Visit stacklok.com to read the docs or talk with our forward-deployed engineers.
November 30, 2026