The Next Stop for Agent Runtime Environments: Context and Memory
This article examines why runtime frameworks, rather than base models, have become the main bottleneck for AI agents, and why execution environments have matured while memory systems remain thin. It outlines four hard requirements for long-running agent environments—isolation, snapshot and restore, elastic scaling, and observability—and breaks context and memory into four layers: working, episodic, semantic, and procedural. It also covers how to turn memory into an accumulating engineering asset (what to write, how to store, retrieve, and govern it), patterns for parallel multi-instance execution with shared context and result merging, and the observability, cost, and security controls long tasks require. A practical adoption roadmap is included.
1. Introduction: From “Calling Tools” to “Working Over the Long Haul”
Over the past two years, the engineering focus around large language models has shifted noticeably. Early on, teams competed on the capability of the model itself. Then the competition moved to the surrounding glue layer—the runtime frameworks that connect a model to tools, file systems, terminals, and browsers. The value of these frameworks is not the act of calling a tool. It is that they gave models “executable hands and feet” for the first time.
But a more important question follows. If an agent can run locally or in the cloud through a glue framework, can the same task be handed off between local and cloud? Can multiple instances that share context run in parallel in isolated environments, compressing work that would normally take months or even years into a much shorter cycle?
Films have long offered a vivid image of this: an overhead shot of a grid of cubicles, countless workstations busy at once. In engineering reality, though, it points to a very concrete problem first—agents need a runtime environment that is stable, isolated, and elastically scalable.
It is worth noting that the underlying capabilities supporting all this—cloud computing, containers, virtualization, distributed storage—were already mature before the LLM boom. So the new constraint does not come from “can it run,” but from “what is left behind after it runs.”
Survey-style research has already made a blunt judgment: runtime frameworks are becoming the main bottleneck on agent capability, not the underlying model. One such review breaks the open-source ecosystem into layers. The execution environment and sandbox layer has the most and most mature projects, while the context and memory management layer is clearly the thinnest, with very few standalone components—most are embedded inside frameworks as an auxiliary feature. The most mature layer and the weakest layer are two sides of the same thing.
2. Why Execution Environments Are Mature but Memory Systems Are Weak
Execution environments answer “where does it run.” Memory systems answer “what does it remember.” These two questions look independent, but each is a precondition for the other.
Give an agent a virtual machine in the cloud and it can write code, get online, manipulate files, and call the command line. But when the task ends, the machine is usually destroyed, and the next launch starts from zero. This is like moving a person into a brand-new office every day: new desk and chairs, a blank desktop, and only a résumé in the drawer. They can work, but they cannot accumulate experience, let alone form a methodology.
More importantly, the shape of tasks is changing. Industry data reflects a clear trend: the average runtime of a single sandbox grew by more than an order of magnitude over one year, showing that agents are moving from short tasks that “finish in a few minutes” to long tasks that last “hours or even days.” Whether it is a cloud agent instance or one of the various cloud workspace products, the essence is simulating a complete human workflow inside a virtual computer. The sandbox has gone from a temporary tool to a long-term workspace, and memory systems have not kept pace.
This creates the most typical mismatch today: runtime environments already support long-term operation, but memory mechanisms still assume one-off sessions. The consequences are three recurring problems:
- The context window is repeatedly “filled and truncated,” and critical early information is lost.
- Every cold start requires re-exploring the environment, and the repeated labor is costly.
- When multiple instances run in parallel, there is no shared source of truth, so results conflict and are hard to merge.
3. Four Hard Requirements That Long-Running Agents Place on Runtime Environments
To make the “long-term workspace” idea solid, a runtime environment needs to satisfy at least four requirements, and each one pulls on memory design in turn.
- Isolation: Different tasks, tenants, and branches must not see each other, to prevent files, processes, networks, and credentials from bleeding across. Isolation is both a security requirement and a precondition for parallel experiments.
- Snapshot and restore: The environment must be able to be snapshotted, cloned, and rolled back. A snapshot is not just a disk image; it should also include process state, temporary directory conventions, and a baseline for environment variables.
- Elastic scaling and scheduling: Task volume fluctuates widely, so environments must be created on demand, scheduled centrally, and reclaimed when idle, with support for splitting long tasks into parallel subtasks distributed across multiple isolated environments.
- Observability and auditability: All execution actions, file changes, and network access must leave structured logs, so they can be replayed and traced for accountability.
A simplified pseudocode can express the scheduling skeleton of “environment as workspace”:
# Illustration: split a long task into parallel subtasks, each running in an isolated environmentplan = planner.decompose(goal) # task decompositionenv_pool = sandbox_pool.acquire(n=len(plan)) # request isolated environmentssnapshots = []for sub, env in zip(plan, env_pool):env.restore_from(base_snapshot) # restore from the baseline snapshotresult = agent.run(sub, env) # execute in the isolated environmentsnapshots.append(env.snapshot()) # produce a rollback-able snapshotmemory.commit(sub.id, result) # write key conclusions to shared memorymerged = memory.merge(snapshots) # merge results from multiple paths
The point of this code is not the API but three conventions: baseline snapshot, execution isolation, and externalized conclusions. Conclusions must be externalized to the memory layer, not left inside an environment that will be destroyed.
4. Context and Memory: The Undervalued Core Layer
If the execution environment is the “office,” the memory system is the “archive plus index plus policy.” A practical memory layer usually contains four kinds of memory, each with a different responsibility:
- Working memory: The content of the current task’s context window, emphasizing timeliness and relevance, and requiring strict budget management and compression strategies.
- Episodic memory: What happened in the past, including tool-call traces, failure reasons, and user corrections, used to avoid repeating the same mistakes.
- Semantic memory: Stable knowledge after abstraction, such as project structure, interface conventions, coding standards, and domain terminology.
- Procedural memory: Reusable workflows and script templates that turn “did it once” into “does it right every time.”
These four kinds of memory correspond to four different write timings and eviction strategies. A common engineering mistake is to stuff all information into the context, which bloats the window, raises costs, and dilutes attention. A more reasonable approach is “layered storage plus retrieval on demand”:
User goal├─ Working memory (in-window, budget-limited, rolling compression)├─ Retrieval layer (vector retrieval + keyword retrieval + structured filtering)├─ Episodic memory store (timestamped and task-ID tagged, traceable)├─ Semantic memory store (versioned, written after review)└─ Procedural memory store (templated, executable, testable)
The retrieval layer needs to support both semantic similarity and exact matching: the former suits “find related experience,” while the latter suits “find an exact identifier, error code, or file path.” Relying on a single retrieval method often performs unstably in real engineering.
5. Turning Memory into an Accumulating Engineering Asset
For memory to compound, four engineering problems must be solved.
First, what to write. Not every intermediate step is worth saving. It is advisable to persist only three kinds of content: reusable conclusions, failure patterns and root causes, and the user’s explicit preferences and constraints. Metadata (task identifier, time, source, confidence) should be attached on write to support later governance.
Second, how to store it. Short-term memory goes in low-latency storage, while long-term memory lands in a combination of object storage and databases; large artifacts (logs, screenshots, build packages) store only references, not content. Hot-cold tiering both controls cost and preserves traceability.
Third, how to retrieve it. Retrieval needs a budget: limit the number of returned items, total length, and time window, doing coarse ranking first and fine ranking second. For long tasks, it is advisable to do a “memory consolidation” at the end of each stage, compressing conclusions scattered in the context into structured entries.
Fourth, how to govern it. Memory expires, conflicts, and gets polluted. Versioning, confidence decay, conflict detection, and dual human/rule review are needed. For semantic memory in particular, set a “write threshold” to avoid treating one accidental success as a general rule.
A simplified memory write interface:
memory.write(kind="semantic", # semantic / episodic / proceduralcontent="The project uses 4xx to indicate parameter errors",meta={"task": tid, "ts": now(), "confidence": 0.9},ttl_days=180 # expiration governance)
6. Parallel Multi-Instance Execution: Shared Context and Result Merging
When a task is split across multiple isolated environments running in parallel, the real difficulty shifts from “compute” to “consistency.” Sharing context does not mean sharing the same mutable state; it means sharing the same traceable source of truth. Three workable patterns exist:
- Baseline plus branch: All instances start from the same baseline snapshot, each produces a branch snapshot, and everything is merged at the end.
- Event sourcing: Only append events, never modify history; on merge, replay the events to obtain the final state.
- Authoritative conclusion store: The process can diverge in parallel, but conclusions must be written to a unified store and pass validation.
The merge stage needs a conflict-handling strategy: file-level conflicts use three-way merge, conclusion-level conflicts are resolved by confidence and source priority, and anything that cannot be resolved is escalated to human confirmation. Without this layer, parallelism only produces contradictory results faster.
7. Observability, Cost, and Security
The bills and risks from long tasks grow non-linearly, so governance must be built in:
- Observability: Structured logs plus tracing plus metrics and alerting, supporting full replay of a task.
- Cost control: Set context budgets, retrieval budgets, upper limits on environment lifetime, and idle reclamation.
- Security and compliance: Issue credentials on a least-privilege basis, whitelist network egress, and desensitize sensitive data before it enters memory.
- Quality evaluation: Use repeatable evaluation sets to verify that memory actually improves success rates, rather than just adding words.
8. Suggested Adoption Roadmap
- First, make the execution environment a long-term workspace that is snapshot-able, restorable, and isolated.
- Then introduce layered memory and retrieval budgets, prioritizing “repeated exploration” and “lost key conclusions.”
- Next, open up multi-instance parallelism, with baseline branching and merge resolution to match.
- Finally, complete observability, cost, and security governance to close the loop.
From the perspective of general capabilities on cloud platforms such as Baidu AI Cloud, common categories like container platforms, object storage, message queues, log services, and monitoring and alerting can be combined into the “environment plus memory plus governance” foundation described above. The key is whether the architecture treats memory as a first-class citizen rather than an auxiliary switch inside a framework.
9. Conclusion
The execution environment determines where an agent can go; the memory system determines what it can become. As the sandbox evolves from a temporary tool into a long-term workspace, the next dividing line in the industry will not be whose model is bigger, but who can turn context and memory into an accumulating, restorable, and governable engineering asset. Whoever fills the thinnest layer first will first have an agent that can truly “work over the long haul.”
