Agent in Production
ResilienceLong read

Handling Credential Expiry During Long-Running Agent Sessions

Long-running agents need credentials scoped to each task, not static tokens valid across sessions.

· 10 min read
Cover illustration for “Handling Credential Expiry During Long-Running Agent Sessions”
Resilience · October 13, 2026 · 10 min read · 2,310 words

Budget caps on AI coding agents only work if the platform can halt execution the instant a spending threshold is hit, logging the crossing is not enough. Platforms like Ellipsis enforce this by scoping a dollar or token budget to each session and parking the task the moment the cap is hit, rather than letting a runaway fix cycle burn through an open-ended allowance. That same session boundary, as this piece lays out, is also what makes credentials safe to issue.

Static credentials and runtime-deciding agents

The trouble with credential expiry in long-running agent sessions has very little to do with engineers forgetting to rotate a key. It has to do with the fact that every credential system in wide use today was built for software whose behavior could be known in advance. An LLM-driven agent does not work this way. That unpredictability is not a flaw to be engineered around. Neither one solves the underlying mismatch between how credentials get issued and how agents decide what to do.

Long-running agents and the authorization context that granted them access

A long-running agent is not just a process holding a token. A formal counterexample from Zhu and Wang makes this concrete. But the queue has already accepted the message, so a remote worker can still turn that reservation into a real, protected effect somewhere downstream, so you can't declare the system quiescent on the strength of those three local signals alone. Zhu and Wang call this the authorization-execution gap, and they state precisely what must be checked: not whether a controller sent a stop request, but whether the retired authority has actually lost every remaining path to a future protected effect, and whether every point where an old authorization crosses into new action has been accounted for. Cooperative control signals like MCP task cancellation and A2A cancellation are not proof that every underlying effect has stopped; they are polite requests that a well-behaved system honors. OAuth token revocation invalidates a named token at the authorization server, but it says nothing about a message a different provider already accepted before the cut, a credential derived earlier that is still valid, or a shared agent still operating under a separate authorization root. He and Yu's Continuity Kernel paper identifies a parallel problem at the state layer: without an explicit control plane governing updates, models, tools, and background workers can overwrite state, expose data without an audit trail, or escalate their own privileges, because storage retention by itself does not tell you which state is actually authoritative.

The Blast Radius of a Long-Lived Credential in Production

How much damage a compromised or over-scoped credential does is set almost entirely by how long it lives and how much it can reach, not by how fast the incident is noticed. The LiteLLM supply-chain incident from March 24, 2026 shows this clearly. Multi-agent delegation makes the exposure worse, not better, because one agent can spawn several sub-agents, each carrying its own delegated credentials, and agents as a category need dynamic, context-dependent permissions that the static RBAC scopes defined at provisioning time in traditional IT were never built to express. The CSA's AI Agent Governance Framework Gap research note puts a number on how widespread this is: a large majority of enterprise security leaders lack full visibility into their own AI identities, most don't enforce access policies for those identities at all, and a substantial share report that AI systems already have access to core business platforms, including ERP, CRM, and financial systems, while very few say they govern that access effectively.

Kubernetes static secrets as a failure mode for containerized agent infrastructure

Most production agent deployments run on Kubernetes, and Kubernetes's default secret model is exactly the static-credential failure mode described above, built into the platform. A Kubernetes Secret is base64-encoded, not encrypted: running kubectl get secret -o jsonpath and piping the result through base64 -d recovers the plaintext in two commands. The fix starts below the secrets manager layer. Since Kubernetes v1.22, the recommended approach is a bound service account token obtained through the TokenRequest API: audience-bound, so it names the specific service it's meant for; object-bound, so it's tied to the pod that requested it and dies the moment that pod is deleted; and time-bound, so the kubelet requests a fresh one automatically once the current token crosses a threshold of its TTL, with no separate rotation job for anyone to babysit. That bound token then becomes the identity an external secrets manager authenticates against, rather than some shared platform credential everyone uses. From there, two delivery patterns carry equal weight. The choice that actually matters in either case is scoping the TTL to the task at hand rather than to the convenience of a long-running session: a short-TTL dynamic secret issued for a specific database migration job, not a static key that happens to also work for migrations because nobody ever narrowed it.

The ephemeral credential broker model and the eight components that make it work

The only credential model that fits how LLM agents actually behave is one where credentials get issued at the moment of execution, scoped to what this agent needs for this task on this run, and nothing more. You need an ephemeral credential broker made up of eight distinct components to build that, and each one closes a specific gap the static model leaves open. The CSA's analysis lays out the mechanics: when an orchestrator spawns an agent for a task, it asks the broker for a credential and specifies what the agent needs, the broker checks that request against the application's permission ceiling (the maximum scope that application was ever allowed to grant in the first place), and it issues a token scoped to exactly that task, no broader and no longer-lived than necessary. The eight components, as defined in version 1.3 of the Ephemeral Agent Credentialing pattern, work together as a system. Task-scoped tokens are JWTs scoped to exactly the resource and action the task requires: the orchestrator declares the scope and the broker enforces it against the permission ceiling; the default TTL is five minutes, and if a task runs long, it renews before expiration under the same identity with a fresh TTL and the same or narrower scope, capped by a renewal limit, so an agent can extend its time but never expand its permissions. Key-bound credentials tie each token to a private key the agent holds, so a stolen JWT is useless by itself without that key, and that removes the replay attack surface bearer tokens otherwise create. Zero-trust enforcement runs mutual TLS at the transport layer and JWT validation at the application layer on every request, and it grants no implicit trust from network location or a prior successful authentication. Four-level revocation lets an operator pull a single token, all tokens for an agent, all tokens for a task, or all tokens across an entire delegation chain, propagating in under 30 seconds, with automatic expiration handling the routine case and revocation reserved for incidents. The arithmetic behind this is stark: a system running many concurrent agents that finish tasks in minutes but hold standard 15-minute OAuth tokens accumulates a large pool of agent-hours every day during which a stolen credential stays valid for work that already finished, and task-scoped, key-bound credentials that expire at completion collapse that window to nearly nothing. The four-level revocation hierarchy is the direct answer to the Zhu and Wang authorization-execution gap described earlier: it doesn't stop at revoking a single token at the authorization server, it propagates across the whole delegation chain, accounting for the sub-agents, callbacks, and delegated credentials that a simple token revocation would otherwise leave running.

Sandbox isolation and YAML-driven agent configuration as infrastructure-layer credential scope enforcement

None of the broker model above means anything if agent sessions share an execution environment where one session can read another's credential store. Isolation at the sandbox layer is what physically enforces the scope the credential broker only guarantees on paper, and writing that isolation into YAML config checked into a repository is what makes it something a reviewer can actually audit. GKE Agent Sandbox reached general availability in May 2026 and introduces a set of Kubernetes-native abstractions built around this idea: Sandbox as the core stateful workload resource, SandboxTemplate as the environment blueprint, SandboxClaim letting frameworks request execution environments declaratively, and SandboxWarmPool keeping pre-booted sandboxes ready so a claim doesn't have to wait on a cold start. Kata Containers runs a lightweight VM per pod: it trades a bit of memory overhead and slower startup for stronger isolation, and that fits agents running shell or Python tools. Confidential Containers built on TDX or SEV-SNP add a hardware enclave, and that suits regulated data where you can't trust the host itself. NVIDIA's OpenShell builds on the same pattern with a declarative YAML policy engine paired with a gateway control plane and credential providers, running across Docker, Podman, Kubernetes, or MicroVM compute drivers. WorkOS's analysis separates the credential problem into three distinct layers that all need to work together: the secrets store itself, encrypted at rest, access-controlled, and audited; the OAuth connection management layer; and the session-scoped access layer, with environment variables and config files ruled out as secure storage for any of the three. In multi-tenant deployments, different customers' credentials need separate encryption keys so that compromising one customer's key doesn't expose another's data, and those keys ideally live in a hardware security module or a cloud KMS, managed apart from the data they protect. Ellipsis operationalizes exactly this pattern: agents are defined as YAML config files checked into repositories, run inside isolated cloud sandboxes, and credentials are minted fresh for each session and revoked the moment that session ends, with the sandbox boundary itself acting as the enforcement mechanism for the scope declared in the config.

MCP server exposure beyond the Kubernetes credential model

Locking down the platform identity layer, meaning how the agent authenticates to the cluster, still leaves open the credentials that agent hands off to the tools it calls in the middle of a task. Much of the open-source MCP server ecosystem still runs on exactly the static credential patterns described above. Among more than 5,200 open-source MCP server implementations analyzed (5,205, specifically), a large majority require some form of credential, and roughly half of those rely on long-lived static secrets, API keys and personal access tokens with no expiry date. The fix at this layer mirrors the broker model described for the platform layer: a central token broker holds the actual OAuth credentials, the MCP server or gateway never touches them directly, and a request from the agent for a given tool call routes through the broker, which issues a short-lived token scoped to that one call. WorkOS's analysis frames the three layers, secrets store, OAuth connection management, and session-scoped access, as needing to operate together, and a team that locks down the Kubernetes identity layer while leaving MCP servers pointed at long-lived environment-variable keys has only closed half the problem. In a multi-agent workflow built on chained calls, a credential compromised mid-session doesn't stay contained to the agent that was compromised; it propagates to every downstream tool call that agent has already set in motion, which is exactly the scenario the delegation chain verification component from the broker model is built to answer.

Observability requirements that make session-scoped credentials governable in practice

Ephemeral credentials that leave no trace of what they actually authorized provide no governance. If you have full visibility into every credential issuance, renewal, tool call, and revocation event, that turns the session-scoped model from a security property into something an engineering team can actually audit. Three categories of information need to be recorded and joined together: what the agent did, meaning its traces, sessions, tool calls, sub-agents, and the rules and skills it loaded; what it cost, in tokens, cache hits and misses, and dollars or credits per session; and what it produced, the pull request, the CI result, and any rework needed before merge. The EU AI Act mandates automatic logging for high-risk AI systems, with key obligations now deferred to December 2, 2027 for Annex III systems, moved from the original August 2, 2026 date under Regulation (EU) 2026/1744, and penalties for non-compliance reaching €15 million or 3% of worldwide annual turnover, whichever is higher. For affected teams, demonstrable AI governance has stopped being a best practice; it is now a legal requirement. WorkOS's credential analysis points out that shared service accounts make individual agent behavior impossible to attribute: if one of several agents sharing an account takes a destructive action, the audit trail shows only which account was used. Session-scoped credentials tied to unique agent identities are the prerequisite for solving that, and attribution is the prerequisite for an audit trail worth having. Ellipsis logs every tool call, diff, and token and ties each one to a person or trigger, running sessions on credentials minted for that session specifically and revoked the moment it ends, making the audit trail a structural property of how the session works.

Choosing the right managed runtime

Every governance property described above, ephemeral credentials, sandbox isolation, delegation chain verification, full audit logs, is only as strong as the runtime actually enforcing it. How managed-cloud, bring-your-own-cloud, and self-hosted options trade off maps directly onto which of those properties each one can deliver on its own. The platform is SOC 2 Type I certified and built for engineering teams that need governance, meaning scoped credentials, budget caps, and audit trails, running alongside automation as a built-in property of it. The right choice depends on what a team is actually optimizing for. Whichever runtime a team picks, the underlying principle holds regardless: the session is the unit of governance, and credentials should be artifacts of that session rather than preconditions imported from somewhere else.

Sources

  1. AI Agent Identity Is Solved Backwards
  2. Beyond Memory: A Transactional Continuity Kernel for Long-Lived AI Agents
  3. Authorization Revocation for Long-Running AI Agents: Root-Scoped Quiescence under Delegation and Asynchronous Execution
Filed underResilience

More in Resilience