SubscribeSign In
Agent to Product

How Shared Agent Runtimes Leak Context and Why Sandbox Isolation Is the Architectural Fix

Shared runtimes leak user context by design, and sandboxes fix it.

· 9 min read
Cover illustration for “How Shared Agent Runtimes Leak Context and Why Sandbox Isolation Is the Architectural Fix”
API-First Provisioning · November 12, 2026 · 9 min read · 1,955 words

Shared agent runtimes leak context because they retain state across users. Per-user sandbox isolation fixes that structural problem by separating each user’s memory, files, and credentials. Managed hosting can set up a separate, persistent AI agent sandbox through a single API call, so each customer has a private environment and the product team does not have to run the infrastructure.

Why shared agent runtimes leak context by design, not by accident

A customer’s agent session shows context that belongs to someone else. For the founder or operator discovering it, the immediate question is which bug let that happen. That question makes sense, but it starts too late. If both customers’ agents run inside an environment that retains their state, the opportunity for crossover existed before the unexpected response. The response exposed a boundary the runtime never enforced.

Accidental leakage and structural leakage are different problems. A bug that exposes one user’s data to another may be fixable with a patch. Structural leakage happens when users’ memory, tool state, or session context is kept in a shared address space. Patching a particular access path does not remove that shared state. The next capability still runs in an environment where it may have access to another user’s context.

Pooling is doing what it was built to do. It reuses a running environment across users. The danger is treating that reuse as though it also resets ownership of everything the environment holds. In production agent systems, this structural exposure is the central risk because it reaches beyond any single faulty response or tool call.

What a shared agent runtime actually holds in memory between users

A running agent retains conversation history and context windows, including prior turns that its reasoning loop may reuse or reference. It can also retain tool results from API calls, file reads, and database lookups. Those results may sit in process memory or in a cache shared by the runtime. Those results may still be there after the conversation ends.

The agent also has working state between tool calls. In-process variables can hold intermediate reasoning steps, scratchpad content, and task chains that are only partly done. These belong to the task that produced them. A process-scoped object can outlive the request that first populated it. Its lifetime follows the process.

API keys and tokens injected into a running process may lack an explicit boundary tying them to one user. Temporary files, downloaded assets, and generated outputs can stay on shared disk paths. Environment variables, loaded libraries, and monkey-patched modules also form part of the execution environment. One invocation can change process-level state that another invocation later uses.

Garbage collection, caching, and connection pooling create windows in which an earlier user’s state persists into the next execution context. Not every retained object will be exposed in an answer. The important distinction is that ending the session does not, by itself, make its state inaccessible to the next user.

The four structural pathways through which state crosses user boundaries

The first pathway is process memory reuse. Worker-pool designs reuse a runtime process across requests, and heap memory from an earlier session may not be zeroed before another begins. Retained bytes alone do not explain how context reaches an agent. A concrete route is an agent framework’s process-scoped “current context” object. One session mutates that object, and a later session reads stale values because the request boundary did not fully reset it.

The second pathway is a shared cache. A tool result, embedding lookup, or retrieved document may be cached under a content key. For example, two users’ documents could share a topic phrase that produces the same cache key. The second user’s lookup can then receive the first user’s cached result.

Semantic caches widen that overlap further. They match queries by embedding similarity rather than requiring identical text, so differently worded questions can reach the same cached answer. Without a user-scoped key, though, similarity can let one customer reach another customer’s data. The cache can return a technically valid hit that belongs to the wrong person.

The third pathway is the shared working directory. An agent may download a file or write an intermediate output to a temporary path that other agents in the environment can read. That artifact remains available beyond the tool call that created it. Concurrent sessions add another risk, because one agent can read a file while another is still writing it. This can happen even if neither agent asks for another customer’s data.

The fourth pathway is credential scope collapse. When API keys, OAuth tokens, or database credentials are put in process environment variables at startup, sessions in that process get access to those credentials. A tool call can therefore use an identity that does not belong to the current user. An email, calendar, or CRM integration may accept the call because the credential itself is valid. Even when authentication succeeds, it does not show that the right customer approved the action.

Why policy-level controls cannot close these pathways

Careful engineering can do a lot to limit leakage through all four pathways. Explicit context teardown limits stale working memory, per-request cache namespacing separates cached results, and credentials injected per call narrow their scope. This is the strongest argument for keeping a shared runtime. It deserves more than a dismissal about engineers making mistakes. A disciplined team can build meaningful safeguards around pooled execution.

Every safeguard must cover every path it protects, including new paths that come with each tool or capability added to the agent. After a context reset, files are still shared, and with a private cache key, process-level credentials are still in place. Each control protects its own boundary.

Prompt instructions cannot keep users’ state separate in the runtime. An instruction such as “do not reveal information from other users” reaches the model after the wrong context may already have been loaded. The model can leave that context out of its quotes while still using it in its reasoning. Middleware content filters have a similar limit because they check the output the model has produced. A filter may catch copied text but miss that private context helped shape the answer.

Session-scoped authentication tokens solve a different problem again. They establish who initiated the session. Rate limiting controls how often access is allowed, while tenant tagging labels what happens. Neither creates a memory boundary.

Instead of requiring every tool to avoid state that is already within reach, the runtime places that state outside the user’s environment. Policy can then govern behavior inside the boundary. It no longer has to stand in for the boundary itself.

What sandbox isolation actually means at the runtime level

A sandbox is a separate execution environment for one user’s agent. It has its own memory space, file system, credential scope, and network identity. Calling a session “private” does not isolate it if its agent still shares process-level state with other users. The separation must exist below the application’s instructions.

A process or container boundary provides memory separation enforced by the operating system. One user’s agent cannot use the shared-context routes described earlier to read another user’s process memory. The file system needs an equivalent boundary. Each sandbox starts with a fresh, isolated file system mount, so files written by one user’s agent are not readable by another. Anything meant to survive a session is explicitly persisted to a user-scoped store.

Credentials must follow the same ownership rule. Secrets and tokens are put in the sandbox at startup, belong only to that user, and are kept out of shared environment variables. Network namespace separation keeps one sandbox’s outbound activity separate from another’s, while those calls use the user’s own credentials. Any caching layer also needs keys that include a user-scoped identifier. Otherwise, a shared cache would reopen a route the execution boundary was meant to close.

Isolation does not require an agent to forget. Conversation history, files, and tool state can persist durably outside the sandbox in storage scoped to that user. At the next startup, that state is injected back into the user’s environment. “Isolated but persistent” describes a different architecture from “shared and stateful.”

That distinction makes persistence part of the boundary design. The boundary design must account for where state survives and which environment can load it. A user’s experience can last across sessions without keeping a pool of mixed customer state alive. It requires durable ownership across sessions.

The operational consequences of choosing isolation as the default architecture

Isolation changes the shape of an agent failure. When one user’s agent crashes, hangs, or behaves unexpectedly, the failure is contained within that user’s sandbox. The boundary exists before the incident begins. Operators do not have to depend on a failed agent completing its cleanup correctly to protect the next session.

The same separation makes actions easier to attribute. Because a sandbox’s state belongs to one user, its agent’s actions can be tied to that user’s context and credentials. Audit logs then describe activity within a defined ownership boundary. That gives compliance claims a firmer basis than a tenant label attached to pooled execution. The record and the runtime refer to the same unit.

Customer-facing promises become more concrete as a result. An operator can say that the customer’s agent runs in its own private environment with its own credentials. Those runtime boundaries are especially important when an agent can act through tools. Privacy includes whose identity it uses to act.

Growth follows the same unit of separation. The system scales horizontally by adding isolated sandboxes, while keeping more users’ state out of a shared pool. Each new customer gets another bounded environment. Growth still brings infrastructure work, but it does not mean more customers have to keep their state in the same runtime.

There is a resource premium to isolation, especially at small scale. Container runtimes and micro-VM technology have reduced the marginal cost, while a cross-tenant leak can bring customer churn, breach notification obligations, and reputational damage. At product scale, those incident costs can outweigh the resource savings of pooling. The remaining obstacle is often operating all the separate environments.

How can operators give every user a persistent agent sandbox through a single API call?

Managed hosting makes per-user sandbox provisioning the platform’s responsibility. A single API call can activate a new isolated, persistent agent sandbox when a customer is onboarded. The operator requests the environment rather than assembling its execution boundaries. This follows the same division of work as a payments API activating a billing account without the product team running payment infrastructure. The product owns the customer workflow. The hosting layer owns provisioning.

Provisioning is only the first part of that responsibility. Each environment needs the right credentials and configuration without mixing them with another customer’s settings. Its health must be monitored independently, and it needs recovery when it fails. Agent updates must reach environments that are running without downtime or loss of state. Usage tracking and billing also need to follow each user’s sandbox.

For operators choosing a hosting layer, those are concrete criteria. A service that creates a separate session identifier has not necessarily created a separate execution environment. The relevant questions concern memory separation, private files, user-scoped credentials, cache ownership, and durable state across sessions. The service also needs to handle the operational lifecycle after creation. A simple provisioning call is useful only if the environment behind it has the required boundaries.

The practical choice is therefore which hosting layer enforces isolation structurally and operates it for the product team. That frees the team from keeping custom teardown rules up to date as its set of tools changes. The operator can connect customer onboarding to a provisioning API while the platform handles the separate environments beneath it.

Sources

  1. Trustworthy Agentic AI Requires Deterministic Architectural Boundaries
  2. An AI Agent Execution Environment to Safeguard User Data
  3. Authorization Before Context: A Model-Neutral Audience Boundary Against Cross-Audience Memory Leakage in Agentic Systems
  4. Sandlock: Confining AI Agent Code with Unprivileged Linux Primitives
  5. Governed Shared Memory for Multi-Agent LLM Systems
  6. Isolation as a First-Class Principle for LLM-Agent System Safety: Concepts, Taxonomy, Challenges and Future Directions

More in API-First Provisioning