Beyond Git Worktree

Persistent vs Ephemeral Remote Environments for Coding Agents

Choosing a sandbox lifecycle early saves agents from costly rebuilds.

· 10 min read · Updated
Cover illustration for “Persistent vs Ephemeral Remote Environments for Coding Agents”
Remote Agent Environments · September 21, 2026 · 10 min read · 2,253 words

An agent clones a repository, installs its dependencies, reproduces a failing test, and gets three-quarters of the way through a fix. The sandbox hits its duration limit. The next invocation starts in an empty directory with the same task, the same prompt, and none of the evidence of the work already done. Nothing crashed and nothing errored: the work was simply never written anywhere durable, because the environment it lived in was built to disappear. That single failure illustrates why the choice between an ephemeral and a persistent environment cannot be left to a platform default chosen after the workload is already designed. Teams tend to encounter this question at the wrong moment, after a platform has already been selected, when it should be one of the first structural decisions made about how a coding agent will run. What makes coding agents different from earlier CI jobs or serverless functions is sustained execution: the agent reasons across multi-step sequences, calls tools, reads the results, and adjusts its next move based on what it finds, so the environment functions as a workspace it returns to rather than a runtime it passes through once. Get the lifecycle wrong in one direction and an agent re-pays a setup cost on every single call. Get it wrong in the other direction and a workspace quietly accumulates broken installs, stale credentials, and half-finished state that nobody can cleanly attribute to the code or the environment. Both failure modes are expensive in ways that compound, and that is why the decision belongs upstream of platform selection, not downstream of it.

Ephemeral and Persistent Environments at the Infrastructure Level

The operative difference between the two patterns is lifecycle: an ephemeral environment is created for a single task and destroyed the moment that task ends, while a persistent environment survives the end of a session and resumes from where it left off. In the ephemeral model, the platform boots a fresh container or microVM from a stored image, runs the agent's code, captures whatever output it produces, and tears the whole environment down, releasing its resources immediately. Nothing carries over between invocations unless it was deliberately exported somewhere else: the filesystem, any installed packages, and any running processes all vanish with the sandbox. In the persistent model, a finished task moves the sandbox into standby instead of destroying it, and the next invocation restores from that saved state rather than booting from a blank image. So a persistent environment pays its setup cost once and then amortizes it: an agent can resume work in milliseconds instead of re-cloning a repository and reinstalling a dependency tree on every call.

A rough comparison makes the mechanics easier to hold in view:

| Property | Ephemeral | Persistent | |---|---|---| | Lifecycle | Created per task, destroyed after | Survives and resumes across sessions | | What survives | Nothing, unless exported | Filesystem, packages, repos, caches, written artifacts | | Setup cost | Paid on every invocation | Paid once, amortized afterward | | Idle cost | Zero, environment does not exist between runs | Depends on whether the platform bills reserved compute or decouples storage from compute | | Leftover risk | None by design | Accumulated state can drift or go stale | | Typical work | Short, isolated, or untrusted tasks | Long-running, context-dependent work |

It helps to keep the isolation model separate from the lifecycle model, because they answer different questions. A microVM provides hardware-enforced isolation whether the environment around it is ephemeral or persistent. The lifecycle decides how long a mistake is allowed to live, not how easily a mistake happens in the first place. Production agent platforms draw on a handful of isolation primitives, hardened containers, a sandboxed runtime, and microVMs among them, each with its own tradeoffs for multi-step, stateful execution. MicroVMs have become the standard for production multi-tenant agent platforms precisely because a compromise of the guest kernel does not hand an attacker a path to the host kernel.

The workload properties that determine which lifecycle fits

Everything in this decision reduces to one question: does the agent's next action depend on state that a prior session produced? If the answer is no, ephemeral execution fits. One-shot data transforms, generating a chart from a CSV, validating a webhook payload, transforming a JSON object, round out the category.

If the answer is yes, persistence becomes close to mandatory. A coding agent working inside a cloned repository depends on the repo itself, the dependency tree, the build cache, a local database, and any notes it has written along the way, all of which are slow to rebuild and pointless to discard between turns. If a multi-day or scheduled agent forgets everything overnight, it fails the test of autonomy, since it can only function as a session tool when it cannot remember its own prior session.

The complication is that both shapes often appear inside the same product, sometimes inside the same session. A coding agent might fan out a batch of ephemeral evaluation runs while it keeps one persistent workspace for the actual repository it is editing. That mixture is what turns lifecycle into a platform-level design question rather than something decided task by task. A workable diagnostic cuts through most of the ambiguity: if the second run has to rebuild everything the first run already built, the lifecycle chosen for that workload is wrong.

How a mismatched lifecycle imposes costs on every run

The cold-start tax on a mismatched ephemeral environment is rarely the sandbox boot time itself. It is the cloning, the dependency installation, and the cache-warming that follow the boot, and those costs repeat on every single invocation rather than being paid once. That repetition compounds across an agent's reasoning loop: a coding agent spending most of its session time rebuilding its own workspace is paying the mismatch tax on every tool call it makes, not merely at the start of the session. Because agents multiply cost through repeated model calls, retries, and chained context, a corrupted or malformed step introduced early in a session can influence every step that follows it, which makes reconstruction loops costly in raw compute and dangerous in the way they amplify a single bad step.

The inverse mismatch carries a different kind of tax. Multi-agent concurrency adds another layer of cost to this picture: each agent working in parallel needs its own isolated workspace, ideally its own git worktree, so that simultaneous edits do not collide. If you skip that isolation, parallelism turns into contention over shared state instead of genuine throughput.

Idle billing is where the persistence decision becomes economically workable or prohibitively expensive. A platform that bills wall-clock time for an idle sandbox makes persistence costly for any agent that spends a large share of its time simply waiting on a model response. A platform that decouples state preservation from compute billing changes that math. Infrastructure platforms like Ellipsis that separate storage from per-second compute charges let a team choose the lifecycle the workload actually needs without being penalized for keeping a workspace alive between calls, which turns the lifecycle decision back into a question of workload fit rather than a forced tradeoff against cost.

The security surface each lifecycle creates

The strongest case against defaulting to persistence has nothing to do with performance. Persistent environments accumulate shell history, cached credentials, and installed packages across sessions, so a sandbox compromised once stays compromised until something actively intervenes. Ephemeral environments bound that risk by design: a poisoned dependency or an injected credential dies along with the sandbox the moment the task ends.

Lifecycle and isolation remain separate concerns here, and conflating them is a common mistake. The controls that actually close the persistent-environment gap are concrete rather than abstract. Checkpoints give the system a known-good snapshot to restore to whenever the current state stops being trustworthy, providing the substrate for rollback, a capability the research literature on always-on agents identifies as the rarest and least-studied part of the agent lifecycle. A reproducible base image that the agent cannot dirty keeps its changes confined to a layer that can be inspected, snapshotted, and discarded independently of the underlying environment. Platforms that run agents at scale need to make these isolation and lifecycle decisions explicit, not implicit. Ellipsis, for instance, runs agent sessions in isolated cloud sandboxes where each session receives its own minted credentials that are revoked on completion, paired with full audit trails of every tool call and diff, so the governance layer contains a poisoned dependency or a failed session regardless of which lifecycle pattern the workload calls for.

The research survey on always-on agents finds that the literature concentrates far more heavily on accumulating and retrieving state than on governing, recovering, or relinquishing it, and that imbalance is visible directly in production deployments, where governance is consistently the most under-built piece of the system. Teams operating under strict compliance regimes, finance, healthcare, government, sometimes choose ephemeral execution deliberately and accept the repeated setup cost as the price of a smaller, simpler attack surface. That is a legitimate architectural choice rather than a failure to understand what persistence offers, and the point is to make it consciously rather than by default.

Governance, observability, and state management in a persistent agent environment

Persistent state in a coding agent is not limited to the filesystem. It includes task ledgers, permissions, credentials, commitments, provenance and audit records, shared state between agents, trigger conditions, and side effects already committed to external systems, and each of these categories needs its own governance treatment rather than a single blanket policy. The literature on always-on agents proposes six diagnostic axes to apply to each piece of state: authority, meaning who wrote it; scope, meaning what it applies to; mutability, meaning whether it can be changed; provenance, meaning where it came from; recoverability, meaning whether it can be rolled back; and actionability, meaning what it unlocks once read. A production deployment needs a working answer to all six for any state it keeps around.

The validation stage of that lifecycle is the one most often skipped in practice, and state written without validation corrupts every later step that reads and acts on it, often silently. Agent identity matters at the same level of rigor: each agent needs a unique identity distinguishable in logs, permissions scoped to the minimum its function requires, and credential grants that are time-bounded rather than permanent.

A growing number of teams manage this through agents-as-code: prompt changes, guardrail updates, and policy revisions committed with a diff, an author, an approval signature, and a deploy timestamp, with Git serving as the source of truth and the platform pulling versioned configuration at deploy time. So that pattern brings agent governance into the same review and audit workflow the rest of engineering already uses, instead of treating agent behavior as something configured outside of it. Rollback deserves particular attention because the literature identifies it as the rarest capability across the state lifecycle. Most platforms simply do not support it well today. Teams building on persistent environments need to design checkpoint-and-restore explicitly into their own systems, because they cannot assume the platform will give it to them for free.

How to evaluate infrastructure platforms against these lifecycle requirements

Choosing a platform against this framework starts with whether it supports both ephemeral and persistent environments or only one, and if it only supports one, whether that limitation actually matches the shape of the workload a team is running. What persistence means concretely on that platform matters next: "persistent" can mean filesystem only, or filesystem plus process memory, and that distinction decides whether standby preserves state without continuing to bill for compute the whole time. Isolation model matters just as much as lifecycle support: containers, gVisor, and microVMs offer meaningfully different security guarantees, and for untrusted or agent-generated code running at scale, microVM-level isolation gives each workload a dedicated kernel rather than a shared one. Deployment flexibility is worth checking directly, specifically whether a platform can run inside a team's own cloud infrastructure, bringing your own cloud across an existing provider, or only on the vendor's managed cloud, since that choice has direct consequences for data sovereignty and for where credentials and code ever leave a team's own network boundary. Startup speed and concurrency limits need to be tested at the scale the workload will actually run at, not at the scale of a demo. Governance capability is a separate line item from isolation and lifecycle entirely: a platform should offer scoped credentials, session-level audit logs, and budget controls as built-in features. Finally, a platform's actual support for rollback or checkpoint-and-restore in persistent environments deserves direct scrutiny, since this is the capability research consistently finds weakest across the industry and the one most platforms quietly assume someone else will handle.

A broader tension between managed platforms and self-hosted infrastructure runs through most of these questions. Managed platforms trade some control for operational simplicity, but self-hosting trades that simplicity for data sovereignty and, at sufficient scale, potentially better unit economics. Neither answer is universally correct, and the compliance regime a team operates under often settles the question before cost or convenience even enter the conversation. Because lifecycle, isolation, and governance are frequently bundled together as a single package by vendors, understanding them as three separate decisions, each with its own set of requirements, gives a team the leverage to evaluate a platform on its actual merits rather than on how the sales page groups its features.

Sources

  1. Always-OnAgents:A Survey of Persistent Memory, State, and Governance in LLMAgents

More in Remote Agent Environments