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.
| Ephemeral | Persistent | |
|---|---|---|
| Lifetime | One task | Days to months |
| Starting state | Known image, identical every time | Whatever the last task left |
| Setup per task | Every time | Once |
| Idle cost | None | Disk at minimum; compute if left running |
| Blast radius of a bad task | That task only | Every later task |
| Reproducibility | High | Drifts over time |
| Typical tech | Containers, gVisor, microVMs, sandbox services | VMs, 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.
| State | Example | Where it belongs |
|---|---|---|
| Task history | Every model call and tool call | Database, keyed by task ID |
| Long-term memory | Facts about a user or project | Database plus a vector index |
| Working files | Downloaded CSVs, generated reports | Sandbox during the task; object storage after |
| Installed environment | Python packages, CLIs, browsers | Container image or a persistent disk |
| Caches | Package caches, build caches, model weights | Persistent disk or a shared cache volume |
| Running processes | A dev server, a Jupyter kernel, a long training job | Only 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:
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 /workThe 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.
| Approach | Setup time per day | Compute spent on setup | Other effect |
|---|---|---|---|
| Ephemeral, rebuild each task | 30 × 8 min = 240 min | 4 hours of sandbox time | Agent re-explores the repo every task: more tokens |
| Persistent workspace | 8 min once | ~0.13 hours | Must reset the working tree between tasks |
| Ephemeral from a snapshot of the built workspace | ~seconds per task | Rebuild snapshot daily | Best 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:
| Policy | Running hours a week | Paused hours a week | Weekly cost |
|---|---|---|---|
| Left running 24/7 | 168 | 0 | 168 × $1.59/hr ≈ $267.12 |
| Running 8 h × 5 days, paused otherwise | 40 | 128 | $63.60 compute (40 h) + 128 × 3¢ = $3.84 disk |
| Deleted after each session, rebuilt next day | 40 + setup time | 0 | 40 × $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:
- Rebuild on a schedule. Recreate the environment from its image or bootstrap script weekly, or after any task that failed oddly.
- Reset between tasks. For coding agents,
git reset --hard && git clean -fdxat the start of each task restores the working tree while keeping caches outside it. - Keep credentials out. Inject per-task, short-lived tokens; never store long-lived keys on the disk.
- Log commands outside the environment, so you can reconstruct what happened even if a task tampered with local history.
- Back up what matters to object storage. A persistent disk is a convenience, not a system of record.
# 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_modulesThe -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 type | Environment | State |
|---|---|---|
| Support, triage, routing | None (API calls only) | Database |
| Data analysis, document tasks | Ephemeral sandbox from a pre-built image | Object storage + database |
| Browser tasks | Ephemeral browser per task | Database; no saved cookies unless the task needs a login |
| Coding agent on a large repository | Persistent workspace per repo, reset per task, rebuilt weekly | Git + database |
| Research agent with GPU work | Persistent GPU machine per project, paused when idle | Disk + 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.
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
- Complete guideWhat Is AI Agent Infrastructure? A Complete Guide
- GuideWhat Is a Sandbox Environment for AI Agents?
- GuideWhy AI Agents Need Their Own Computers and Execution Environments
- GuideRunning Coding Agents in the Cloud: Infrastructure and Costs
- ComparisonBest GPU Cloud Providers with Per-Minute Billing
- TutorialHow to Run Autonomous AI Agents on Cloud Infrastructure
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.