Agent governance in three phases: pre-run, runtime, post-run
Pre-run governance decides what an AI agent is given before it starts: the tools, data, identity, execution environment and budget it can use. Runtime governance checks what the agent does as each tool call and model call happens. Post-run governance produces evidence of what it did.
Each phase answers a different question. Pre-run asks what the agent may reach. Runtime asks whether this call is allowed right now. Post-run asks who took which action, under which policy.
This post is for platform engineering and AI enablement teams moving agents from pilots into production on infrastructure they run themselves. We build the pieces that enforce these phases: an MCP registry, an MCP gateway, an AI gateway and an agent harness, all on Kubernetes.
The three phases are a time-based view. We also describe governance by location, as guardrails at three control points, starting with a governed gateway between agents and your data and a gateway between the agent and the model it calls. The two views fit together: each control point acts in one or more phases, and the section on where each phase lives maps them.
Why one phase on its own fails
Teams often treat the phases as three separate checklists. They are one system, and identity is what binds them. Here is what breaks when one phase carries the load alone.
Pre-run only. Scoping is decided once, before anything runs. Then the agent reads a vendor invoice, a support ticket or a web page written by someone outside your company. An agent that reads untrusted content and holds sensitive tools is usually one prompt injection away from calling a permitted tool with the wrong arguments.
Runtime only. A gateway enforces policy on traffic, but something has to decide which servers are approved in the first place. Without a registry, the gateway has no trusted catalog to enforce against. That is why we treat the registry and the gateway as separate jobs; see MCP gateway vs. MCP registry.
Post-run only. Logs are only as good as the identity flowing through them. Most MCP gateways authenticate the user at the front door and then call every backend with a single credential. The gateway’s log shows who asked, the backend’s log shows a service account, and when internal audit asks which person triggered a change, the audit log names nobody.
Pre-run: governing the tools and data an agent is given
Pre-run controls fix the agent’s reach before its first model call. Get these wrong and runtime enforcement spends its time catching problems that should never have been possible.
An approved tool catalog with provenance
Agents should connect only to MCP servers you can trace. Our registry carries provenance attestation and server signing for every MCP server in it, and ToolHive integrates Sigstore and GitHub Attestations for provenance verification (background in from unknown to verified). MCP servers are software dependencies. If one is compromised upstream, provenance is how you know which version you approved.
Segmentation by team
A virtual MCP server (vMCP) is an endpoint that aggregates a specific set of MCP servers. Access to each endpoint is gated by Okta, Microsoft Entra ID or Google Workspace group membership. A typical layout: an engineering endpoint with engineering tools, a finance endpoint with the ERP and BI connectors, and a shared endpoint for tools everyone needs, like Slack or Google Drive. In multi-agent workflows, vMCP lets you compose distinct tool sets for different agent roles, so a specialist agent sees only the tools its task needs.
Decide which tools belong in which segment with your security team before deployment. Finding out through incident response is the expensive way.
Least privilege for every MCP server
Every MCP server runs in its own isolated container with minimal permissions, and its network and filesystem access are set through profiles. In practice that means egress restricted to the specific hosts and ports the server needs, and a read-only filesystem unless a write is genuinely required. Apply these profiles before the server is reachable. An attacker who compromises an upstream MCP server package then gets exactly the permissions you granted it, and no more. Servers run on our MCP runtime.
Identity wired in on day one
Connect your identity provider before anyone connects a real MCP server. Our embedded authorization server supports OIDC and OAuth 2.0, with native integrations for Okta, Microsoft Entra ID and Google Workspace, so wiring in your IdP is a configuration step. Credentials are not stored on developer machines, which is what makes leavers manageable: revoke the person in the IdP and their agents lose access with them. The mechanics are in our MCP authentication and authorization guide.
An execution environment fixed at session creation
Where an agent’s code runs is a pre-run decision too. In Mecatl, our open source agent harness, every session is bound to an execution environment when it is created: the deployment’s default workspace, an operator-approved execution template with a pinned revision, or execution.none, which strips the file and shell tools out of the catalog entirely. The model cannot change its environment mid-run. Whoever created the session made that choice.
Skills count as inputs
A helpful formatting skill shared in a team chat reaches your data just as a connector does. The Skills Catalog in Stacklok Enterprise gives teams a self-serve library of approved skills: admins connect the skill sources they trust and grant skills to specific groups.
Budgets set ahead of time
The AI gateway lets you define budgets and monitor AI spend by team, individual, project and more. Setting the budget is pre-run. Enforcing it is runtime.
Runtime: governing what the agent is doing, call by call
Runtime controls evaluate each tool call and model call as it happens. The important design question is where the check lives. If it lives in a gateway or harness, it sees every call. If it lives in framework code, it sees only the calls a developer remembered to wrap.
Per-request identity, no ambient authority
Every MCP tool call carries an identity token, and we validate that token against your configured identity provider on every request. No session-level authority carries over from one task into the next. A user whose identity token lacks the required group claim receives an authentication failure before the request reaches any MCP server.
Guardrails and secret hygiene
Mecatl’s optional guardrails add a checker model that inspects tool arguments before execution and results before delivery, and they fail closed if the checker is down. Agent-facing shells are secret-scrubbed before a command runs, so provider keys and cloud credentials in the server’s environment do not end up in the agent’s output.
Spend as a runtime ceiling
Cost spikes rarely come from heavy legitimate use. A misconfigured plugin, a looping agent or a tool resending a screenshot every turn is the usual cause, and agents calling other agents multiply it. A budget is only governance if it stops the run: a runaway agent should hit a ceiling before it hits the finance team. More in what good AI spend governance looks like.
Unattended agents
Scheduled and overnight agents have nobody at the keyboard to answer an approval prompt. Mecatl’s server deployments run headless with scheduled tasks for recurring and one-shot runs, under the same permission rules and event history as interactive sessions. On Kubernetes, Mecatl runs headless by default, and an unresolved permission ask is denied unless you have configured a headless-reviewer strategy. An unattended agent cannot quietly approve its own write.
Containing failure
vMCP adds circuit breakers that isolate degraded backend MCP servers, so one failing tool backend does not take down a whole workflow. For the worse case, an MCP server your team approved weeks ago can start making calls nobody recognizes, which is why we argue for a kill switch for your MCP and AI gateways.
Post-run: proving what the agent did
Start from the question an auditor or examiner will ask: at time T, which authorized principal took action A on resource R, under which policy? Post-run governance exists to answer that question.
Every tool call through our gateway produces an OpenTelemetry trace that contains:
- the resolved identity
- the MCP server invoked
- the tool called
- the parameters passed
- the authorization result
Our telemetry aligns with the OTel MCP semantic conventions, so no custom integration layer is required. Traces integrate with Grafana, Datadog, Splunk, New Relic and Honeycomb. Structured JSON audit logs work with Splunk, Datadog, New Relic and Elastic. The evidence lands in tools your operators already run.
The harness adds what a gateway cannot see. Mecatl’s agent loop produces events for turns, tool dispatch, permission pauses and terminal states, and durable deployments keep that event history alongside session state. Permission decisions and tool executions carry audit records. On the model side, spend is attributed by team, individual and project, not just totalled on an invoice.
Before go-live, instrument at least three things:
- Request volume per MCP server and per access group, so you can spot anomalous usage.
- Authentication failures, because an unexpected spike means either a misconfigured policy or an access attempt outside normal patterns.
- Full request metadata for tool calls touching sensitive systems, structured and exported to your SIEM.
Agree with internal audit up front on what the evidence should look like. It is far easier to shape traces before the first review than after it.
Post-run findings should change pre-run settings: revoke a server, re-segment a group, tighten an isolation profile, lower a budget. A governance model where evidence never feeds back into scoping is only half finished.
Identity is the thread through all three phases
The identity you wire in pre-run is the identity enforced at runtime and recorded post-run. Weaken it anywhere and the audit trail breaks: a shared service credential at the gateway, or a sub-agent that inherits its parent’s full authority, means the post-run record cannot say who acted.
Delegation is where most designs slip. In Mecatl, when the main agent delegates, the child receives an authority set that can only narrow the parent’s, and a resumed child is rechecked against the parent’s current authority. Authority on MCP is granted per tool, not per server. Our explainer on agent identity covers why agents break the human-versus-service-account model.
To be clear about what ships: per-request identity through our embedded authorization server, integrated with Okta or Entra ID, is production-ready today. If your security team requires workload-attested identity, you can deploy SPIRE alongside Stacklok: SPIRE handles SVID issuance and rotation, and Stacklok validates the identity at the MCP enforcement layer. Native SPIFFE/SVID integration is on our roadmap, not shipped. Our CTO Joe Beda is a co-author of the SPIFFE specification, and the full architecture is in agentic identity explained.
Where each phase lives in the stack
- MCP registry: pre-run. Which servers exist, and where they came from.
- MCP gateway with vMCP: pre-run segmentation, runtime identity and policy on every agent-to-tool call, and post-run traces.
- AI gateway: pre-run budgets, runtime spend ceilings on agent-to-model calls, and post-run spend attribution. Because it routes inference to the providers you choose, you own the harness, tools, policies and memory and rent the model, so changing providers does not reset your governance.
- Agent harness (Mecatl): pre-run execution environment, runtime permissions and approvals, and post-run event history.
- Unified control plane: one set of policies, IdP integration and control plane across all of it, running on your Kubernetes. See the platform overview and why the gateway, registry and AI gateway solve three different problems.
Where Stacklok fits
We fit teams that already run Kubernetes with a platform team, need data kept behind their firewall, want more than one model provider, and need audit evidence that names people rather than service accounts. Stacklok runs the harness, the MCP gateway, the AI gateway and policy management in your cluster. Because it runs in your environment, it operates under your compliance regime, supports air-gapped deployment and adds no third-party processor to your audit scope.
Our CEO Craig McLuckie and CTO Joe Beda co-created Kubernetes. Our platform secures 20M+ tool calls every month, and ToolHive is open source under Apache 2.0. Teams-specific detail is on our platform engineering and AI enablement pages.
Frequently asked questions
Is this the same as agent guardrails?
They overlap. Guardrails usually describe where controls sit (between the agent and your data, between the agent and the model). The three phases describe when a control acts. Most controls span more than one phase: the MCP gateway segments tools pre-run, enforces identity at runtime and emits traces post-run.
Does my agent framework handle runtime governance?
Partly. Framework pauses run where a developer placed them, so a tool call in a step without one goes through. A harness or gateway applies policy to every call regardless of how the agent’s logic is written. Most teams keep their framework for the agent’s logic and run it on a harness for enforcement.
Should controls come before or after the first pilot?
Before. Identity, segmentation, isolation profiles and observability are much harder to add once teams depend on a live deployment. Starting read-only keeps the pilot fast while the controls are already in place.
Does this make us compliant?
No platform can do that for you. Stacklok provides controls and evidence: per-request identity, tool segmentation, container isolation and audit trails. Your compliance team maps those to your own frameworks.
Can all three phases run without a SaaS dependency?
Yes. The harness, gateways and policy management run in your cluster, with air-gapped support. The one exception is Anthropic MCP Tunnels, which need an outbound connection to Anthropic if you use them.
See the three phases on your own cluster
If you are turning this model into an architecture, book a demo and we will walk through pre-run, runtime and post-run controls for one of your agents. If you would rather start hands-on, ToolHive and Mecatl are open source.
December 03, 2026