Wandering Giants Compute · Learn
Guide

Persistent vs Ephemeral Environments for AI Agents

The short answer

Ephemeral agent environments are created per task and destroyed after it: clean, safe and cheap when setup is fast. Persistent environments survive between tasks: worth it when setup takes minutes or needs a GPU. Most teams combine ephemeral sandboxes with persistent state stored outside them, and pause persistent machines when idle.

Ephemeral
Fresh per task, destroyed after
Persistent
Survives between tasks; keeps tools, files, caches
Deciding factor
Setup time × tasks per day vs idle cost
Best default
Ephemeral compute, persistent state outside it
Wandering Giants paused machine
Disk only, about 3¢ per hour per 50 GB
Disk kept after credit runs out
7 days, free

Every agent system makes this choice, often without noticing: does each task start in a fresh environment, or does the agent come back to the same one? Fresh is clean and safe. Long-lived is fast and remembers. Get it wrong one way and you pay for minutes of setup on every task; the other way and you pay for idle machines and inherit yesterday's mess. This guide sets out the trade-off, the cost maths and the hybrid that most production systems settle on.

What is the difference between persistent and ephemeral agent environments?

An ephemeral environment is created for a single task from a known image and destroyed when the task finishes. A persistent environment outlives the task: its files, installed packages, caches and running processes are there when the agent returns.

EphemeralPersistent
LifetimeOne taskDays to months
Starting stateKnown image, identical every timeWhatever the last task left
Setup per taskEvery timeOnce
Idle costNoneDisk at minimum; compute if left running
Blast radius of a bad taskThat task onlyEvery later task
ReproducibilityHighDrifts over time
Typical techContainers, gVisor, microVMs, sandbox servicesVMs, whole machines, long-lived sandboxes

Neither is "right". The choice is an engineering trade between setup cost and the risks and costs of keeping state around. It sits inside the bigger picture in the AI agent infrastructure guide.

What kinds of state does an agent have?

Separating state by kind is what makes the decision easy, because most of it doesn't need to live in the execution environment at all.

StateExampleWhere it belongs
Task historyEvery model call and tool callDatabase, keyed by task ID
Long-term memoryFacts about a user or projectDatabase plus a vector index
Working filesDownloaded CSVs, generated reportsSandbox during the task; object storage after
Installed environmentPython packages, CLIs, browsersContainer image or a persistent disk
CachesPackage caches, build caches, model weightsPersistent disk or a shared cache volume
Running processesA dev server, a Jupyter kernel, a long training jobOnly in a persistent environment

The first three can always live outside the environment. Only the last three create a real case for persistence, and the last one forces it.

When is ephemeral the right choice?

Ephemeral is right when the environment can be built in seconds and the task doesn't depend on running processes. That covers most agent tool use: data analysis in Python, document conversion, calling a CLI, running a short script.

Its advantages compound at scale:

  • Clean runs. A bug in task 400 can't be caused by something task 312 left behind.
  • Small blast radius. A prompt-injected or broken environment is deleted at the end of the task.
  • No idle cost. You pay only while tasks run.
  • Easy scaling. Any worker can run any task; nothing is pinned to a machine.

The way to keep ephemeral environments fast is to bake everything into the image. If your agent always needs pandas, pyarrow and ripgrep, install them in the Dockerfile, not at the start of each task:

text
FROM python:3.12-slim
RUN apt-get update && apt-get install -y --no-install-recommends ripgrep jq git \
    && rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir pandas pyarrow matplotlib openpyxl
RUN useradd -m -u 1000 agent
USER agent
WORKDIR /work

The model also benefits: an agent that starts in a predictable environment wastes fewer steps (and tokens) discovering what's installed. The agent sandbox guide covers the isolation side.

When does persistence pay for itself?

Persistence pays when setup is slow and repeated. The test is simple: setup time × tasks per day, against what it costs to keep the environment around.

Worked example: a coding agent working on one repository. Cloning, installing dependencies and building takes 8 minutes. The agent runs 30 tasks a day on that repository.

ApproachSetup time per dayCompute spent on setupOther effect
Ephemeral, rebuild each task30 × 8 min = 240 min4 hours of sandbox timeAgent re-explores the repo every task: more tokens
Persistent workspace8 min once~0.13 hoursMust reset the working tree between tasks
Ephemeral from a snapshot of the built workspace~seconds per taskRebuild snapshot dailyBest of both, if your platform supports it

Four hours of setup a day is wasted compute, and worse, four hours of a user waiting. Persistence wins here. The same logic applies to a research agent with a 20 GB dataset, or any agent that needs large model weights on local disk.

GPU environments are the extreme case. Loading a 70B model's weights takes minutes, so an agent that needs a local model (for evaluation, fine-tuning or local inference) should not cold-start a GPU machine per task.

What does a persistent environment cost when idle?

A persistent environment costs its compute price while running and its storage price while paused. The pause is what makes persistence affordable.

Worked example with a Wandering Giants Root machine (an RTX 4090 with a 50 GB disk), used for 8 hours on weekdays:

PolicyRunning hours a weekPaused hours a weekWeekly cost
Left running 24/71680168 × $1.59/hr ≈ $267.12
Running 8 h × 5 days, paused otherwise40128$63.60 compute (40 h) + 128 × 3¢ = $3.84 disk
Deleted after each session, rebuilt next day40 + setup time040 × $1.59/hr ≈ $63.60 + setup minutes

Pausing cuts the compute bill by 128 ÷ 168 ≈ 76% against leaving it running, for under $4 a week of disk. Per-minute billing means the 40 running hours are exactly that, not rounded up. The same pattern applies to bigger GPUs; the disk cost stays about 3¢ an hour per 50 GB, while the compute saving grows with the GPU's price. More on how per-minute billing changes these sums in per-minute GPU billing explained.

Two limits to plan around. Some H200 capacity on Wandering Giants comes from a supplier that cannot pause; we say so before launch, and for those machines "persistent" means "running". And if prepaid credit runs out, the machine stops by itself and its disk is kept free for 7 days, so set a reminder or keep credit topped up for environments you care about.

What are the risks of persistent agent environments?

The main risk is accumulation. A persistent environment collects whatever every previous task did: modified config files, stray credentials, background processes, a package installed by a prompt-injected task. Each one silently affects later tasks.

Controls that keep persistence safe:

  1. Rebuild on a schedule. Recreate the environment from its image or bootstrap script weekly, or after any task that failed oddly.
  2. Reset between tasks. For coding agents, git reset --hard && git clean -fdx at the start of each task restores the working tree while keeping caches outside it.
  3. Keep credentials out. Inject per-task, short-lived tokens; never store long-lived keys on the disk.
  4. Log commands outside the environment, so you can reconstruct what happened even if a task tampered with local history.
  5. Back up what matters to object storage. A persistent disk is a convenience, not a system of record.
bash
# Start-of-task reset for a persistent coding workspace
cd /home/agent/repo
git fetch origin
git checkout --detach origin/main
git reset --hard origin/main
git clean -fdx -e .venv -e node_modules

The -e exclusions keep dependency directories (the expensive part) while removing everything else the last task left.

What hybrid do most teams use?

Most production systems combine both: ephemeral compute for each task, persistent state outside it, and persistent environments only for the few agents whose setup is genuinely expensive.

Agent typeEnvironmentState
Support, triage, routingNone (API calls only)Database
Data analysis, document tasksEphemeral sandbox from a pre-built imageObject storage + database
Browser tasksEphemeral browser per taskDatabase; no saved cookies unless the task needs a login
Coding agent on a large repositoryPersistent workspace per repo, reset per task, rebuilt weeklyGit + database
Research agent with GPU workPersistent GPU machine per project, paused when idleDisk + object storage backups

This keeps the number of persistent environments small, so each one gets proper care, while the bulk of tasks get the safety of a fresh start. Snapshots, where your platform offers them, blur the line further: several sandbox services, including E2B, offer pause and resume of a sandbox, and microVM platforms built on Firecracker can snapshot memory as well as disk. The coding agents guide applies this hybrid to the heaviest case.

How does agent memory work across ephemeral runs?

An agent remembers across ephemeral runs by reading its memory from storage at the start of a task and writing it back at the end. The environment forgets; the database doesn't.

A minimal pattern: at task start, load the last N task summaries for this user or project from Postgres, plus the top few results from a vector search over long-term notes, and put them in the prompt. At task end, ask the model for a short summary of what it did and learned, and store it. Keep memory small and curated: every remembered token is re-read, and paid for, on every step of every future task. A 2,000-token memory block on a 12-step task is 24,000 extra input tokens per task; across 1,000 tasks a day that is 24 million tokens a day spent on remembering. Summarise aggressively, and prefer retrieving the three most relevant notes over loading all of them. The guide on why agents need their own computers covers what belongs on the machine itself.

When does a Wandering Giants machine fit?

A Wandering Giants Root machine fits the persistent end: an agent workspace with a GPU, SSH and a disk that keeps its tools, data and model weights, paused for about 3¢ an hour per 50 GB when no tasks are running and billed by the minute when they are. For the ephemeral end, use a sandbox service or your own container fleet, and point it at a private model on an API GPU so every short-lived sandbox calls the same warm model. See billing and pause pricing.

Frequently asked questions

What is an ephemeral environment for an AI agent?

An ephemeral environment is a sandbox or machine created for one task from a known image and destroyed when the task ends. Nothing carries over, so every run starts clean and a compromised or broken environment simply disappears.

When should an agent have a persistent environment?

When rebuilding the environment is expensive: a large repository and its dependencies, a downloaded dataset, a warmed build cache, or a GPU environment with large model weights. If setup takes minutes and the agent works on the same project repeatedly, persistence saves time and tokens.

Where should agent memory be stored?

Outside the execution environment. Conversation history and step logs go in a database, long-term memory in a database with a vector index, and files in object storage. Then the environment can be ephemeral while the agent still remembers.

Are persistent agent environments less secure?

They carry more risk because anything planted in them, such as a malicious package or a modified config file, persists into later tasks. Mitigate by rebuilding from a clean image on a schedule, keeping credentials out, and logging every command.

How do snapshots help?

A snapshot captures a prepared environment so new sandboxes start from it instead of from scratch. MicroVM platforms can snapshot memory as well as disk, and several sandbox services offer pause and resume. Snapshots give you most of the speed of persistence with the cleanliness of ephemeral runs.

Wandering Giants Compute

Rent the GPU for this, by the minute.

Keep an agent's workspace without paying for idle GPU time: pause a Root machine and pay only for its disk until the next task.

Prepaid credit, billed by the minute, stops itself when credit runs out. Prices in £, $, €, ¥, CA$, A$, CHF and S$; UK prices include VAT.

Keep reading

About this article. Written by the Wandering Giants Compute team, the people who run Wandering Giants Compute. Hardware figures are the manufacturers’ published specifications. Speeds and costs marked as estimates are worked out from those specifications and our current prices, with the method shown; they are not measured benchmarks. Wandering Giants prices are taken live from our price list each time this page is built.

Last reviewed 25 November 2026.