← Blog
SandboxesCI/CDAI agents

Ephemeral environments: for pull requests and AI agents

Yura Dubinin
Yura Dubinin

Ephemeral environments are short-lived, isolated copies of an application or a development machine that are created on demand for one change and deleted when that change is done. Teams use them for two jobs: a preview of every pull request that a person can open in a browser, and a clean machine for every task an AI coding agent runs. There are three common ways to build them: a Kubernetes namespace per pull request, a cloud development environment such as GitHub Codespaces, or a microVM sandbox. They differ most in start time, price per hour and how teardown happens.

If your app fits on one machine, the shortest route is a sandbox per pull request on Lizard (lizard.build). lizard sandbox create -t base -s small --timeout 3600000 starts a Firecracker microVM with 2 vCPU, 4 GB of RAM and a one-hour deadline for $0.0162 an hour, and lizard sandbox expose <id> 3000 gives its port an HTTPS address. The workflow below does this for every pull request and deletes the machine on close. We ran its steps on 15 November 2026.

What is an ephemeral environment?

An ephemeral environment is an isolated environment with a planned end: something creates it automatically for one pull request, test run or agent task, and something deletes it when that work finishes or a deadline passes. It replaces the shared staging server that a whole team queues for.

An event creates it (a pull request, a CI job or an API call), so nobody files a ticket. It holds one branch or one task, so two changes never overwrite each other. A rule deletes it: a merge, a close event or a time limit, and billing stops at that moment.

The same thing goes by other names. A preview environment is an ephemeral environment with a URL for reviewers. An ephemeral dev environment is one a developer or an agent works inside. A CI job on a hosted runner is short-lived too, but it runs a script and exits, while an ephemeral environment stays up so someone can look at it.

Why do teams use ephemeral environments?

Teams use ephemeral environments because a shared staging server lets one change through at a time, and an environment per change removes the queue.

The oldest use is the pull request preview. A reviewer, designer or product manager opens a link and sees the change running before it merges, so the review covers behavior as well as the diff. The same environment serves end-to-end and integration tests: they run against a fresh copy with known data, and a failed run leaves nothing behind for the next one.

The newest use is AI coding agents. An agent writes files and runs commands without asking first. A machine that exists only for its task limits what a bad command can break, and deleting the machine is the cleanup. Coder makes the same argument in "Why Your AI Agents Need Ephemeral Environments" (23 October 2025): its author deleted a workspace an agent had filled with broken code and was working again "in maybe 30 seconds".

The price is extra machinery: something has to create each environment, load data into it, route a URL to it and delete it. Who does that work depends on how you build them.

How do the ways to build ephemeral environments compare?

The three approaches trade completeness for speed. A Kubernetes namespace per pull request can hold a whole multi-service system but takes the most setup. A cloud development environment gives a person or an agent a full editor-ready machine. A microVM sandbox has the lowest hourly price in this table and started in about 3 seconds in our test, but it holds only what fits on one machine. All figures were checked on 15 November 2026 against the linked pages.

Kubernetes namespace per pull requestCloud development environment (GitHub Codespaces)MicroVM sandbox (Lizard Sandboxes)
What you getYour manifests deployed into a new namespace on a shared clusterA VM with your repository and dev container, built for an editorA Linux microVM you drive from a CLI or SDK
StartWith the Argo CD pull request generator: polls every 30 minutes by default, or on a webhook, then the full deploy (Argo CD docs). Qovery describes its own full-stack previews as "minutes, not milliseconds" (Qovery)Not published. Prebuilds shorten itCreate, upload code, start a server and expose a port took 2.6 and 3.0 seconds in our two runs (our own measurement, not a benchmark)
PriceYour nodes, plus $0.10 an hour per Amazon EKS cluster (AWS). The cluster runs whether or not any pull request is open$0.18 an hour for 2 cores, plus $0.07 per GB-month of storage (GitHub)$0.0162 an hour for 2 vCPU and 4 GB of RAM, billed per second, disk included (Lizard pricing)
IsolationNamespaces share the nodes' kernel. The Kubernetes docs suggest sandboxed containers or separate clusters when that matters (Kubernetes)Each codespace runs on its own VM (GitHub)Each sandbox is a Firecracker microVM with its own kernel
TeardownThe generator removes the application when the pull request closesStops after 30 minutes idle by default, has a 12-hour maximum lifetime, and is deleted after 30 days stopped (GitHub)Deleted at the --timeout deadline or by lizard sandbox rm
FitsMany services, queues and databases that must run togetherA person, or an agent, working in an editorSingle-machine apps, test runs, agent tasks

The prices do not describe the same product. A 2-core codespace is a development machine with an editor attached, and the same billing page gives personal accounts a monthly quota and organization plans none. A Kubernetes namespace has no price of its own: you pay for the node capacity it uses.

As plain arithmetic: 30 environment-hours a day (ten pull requests, three pushes each, every environment kept for a full hour) cost 30 × $0.0162 = $0.49 a day on Small Lizard Sandboxes and 30 × $0.18 = $5.40 a day on 2-core codespaces before storage. On Kubernetes the same hours cost whatever spare node capacity you already pay for, plus $73 a month (730 hours × $0.10) for one EKS control plane.

For a system of dozens of services, the microVM row is the wrong one. Read Signadot's Kubernetes guide, which compares cluster, namespace and request-routing models in depth. If you are choosing between Kubernetes and something smaller for the app itself, we cover that in container as a service.

How do you create an ephemeral environment for every pull request?

Create one with a GitHub Actions workflow that reacts to pull request events: on every push it deletes the previous sandbox, creates a new one, uploads the code, starts the app, exposes the port and writes the URL in a comment. On close it deletes the sandbox. The whole file is 55 lines.

You need a Lizard account, an API key limited to one project (lizard keys create ci -p <project>) saved as the LIZARD_API_KEY repository secret, and an app that starts with one command. The example serves the repository with Python's built-in web server. Replace that command with your own.

name: PR preview

on:
  pull_request:
    types: [opened, synchronize, reopened, closed]

permissions:
  contents: read
  pull-requests: write

concurrency:
  group: pr-preview-${{ github.event.pull_request.number }}

env:
  LIZARD_API_KEY: ${{ secrets.LIZARD_API_KEY }}
  GH_TOKEN: ${{ github.token }}
  GH_REPO: ${{ github.repository }}
  PR: ${{ github.event.pull_request.number }}
  HEAD_SHA: ${{ github.event.pull_request.head.sha }}
  PORT: "3000"

jobs:
  preview:
    # Fork pull requests get no secrets, so skip them.
    if: github.event.pull_request.head.repo.full_name == github.repository
    runs-on: ubuntu-latest
    steps:
      - name: Install Lizard CLI
        run: npm install -g @lizard-build/cli

      - name: Delete the environment from the previous push
        run: |
          OLD=$(gh pr view "$PR" --json comments --jq '.comments[].body' \
            | sed -n 's/.*<!-- preview-sandbox:\([a-z0-9-]*\) -->.*/\1/p' | tail -n 1)
          if [ -n "$OLD" ]; then
            lizard sandbox rm "$OLD" --yes || echo "$OLD is already gone"
          fi

      - uses: actions/checkout@v6
        if: github.event.action != 'closed'

      - name: Create the environment and post its URL
        if: github.event.action != 'closed'
        run: |
          SB=$(lizard sandbox create -t base -s small --timeout 3600000 --json | jq -r .sandboxId)
          git archive --format=tar.gz -o /tmp/src.tgz HEAD
          lizard sandbox files put "$SB" /tmp/src.tgz /tmp/src.tgz
          lizard sandbox exec "$SB" -- sh -c "mkdir -p /app && tar -xzf /tmp/src.tgz -C /app && cd /app && nohup python3 -m http.server $PORT --bind 0.0.0.0 >/tmp/app.log 2>&1 </dev/null &"
          URL=$(lizard sandbox expose "$SB" "$PORT" --json | jq -r .url)
          gh pr comment "$PR" --edit-last --create-if-none \
            --body "Preview of ${HEAD_SHA::7}: $URL <!-- preview-sandbox:$SB -->"

      - name: Mark the preview as deleted
        if: github.event.action == 'closed'
        run: gh pr comment "$PR" --edit-last --create-if-none --body "Preview deleted."

The sandbox ID travels in a hidden HTML comment inside the pull request comment, so the next run knows what to delete and the workflow keeps no state anywhere else.

What we tested, and what we did not

We ran the shell steps of this file on 15 November 2026 with Lizard CLI 4.0.128, against real sandboxes in us-east-1, for three events in a row: opened, synchronize and closed. We did not run it on GitHub's hosted runners: the two gh calls were replaced by a stub that kept the comment in a file, and actions/checkout by a local Git repository. The file passes actionlint 1.7.7, and --edit-last and --create-if-none are in the help of gh 2.104.0.

This is the log, shortened and with the access token removed:

=== opened
-- run: Create the environment and post its URL
   exit 0, 2.6 s
comment: Preview of 9052b0a: https://cactus-scheme-d1ma-3000.sandbox.us-east-1.onlizard.com/?lizard_token=REDACTED
GET preview -> 200

=== synchronize
{ "id": "cactus-scheme-d1ma", "status": "deleted" }
-- run: Create the environment and post its URL
   exit 0, 3.0 s
GET new preview -> 200, GET old preview -> 404

=== closed
{ "id": "aunt-sick-hwm2", "status": "deleted" }
comment: Preview deleted.
GET preview -> 404

Four things to know before you copy it

The URL is private by token. expose returns an address with ?lizard_token= in it. A request without the token got HTTP 401 in our test. Anyone who can read the pull request comment can open the preview, so on a public repository treat the comment as public. The preview URLs page explains the token, the cookie a browser gets and the error codes.

The deadline is a backstop. If the close job never runs, the sandbox is still deleted one hour after it started, so a forgotten environment costs at most $0.0162. The deadline is fixed at create time and activity does not extend it. Each push creates a fresh sandbox, which restarts the hour.

The trial fits one pull request at a time. During the 7-day trial an account runs 1 Small sandbox at once (plus 2 Mini), in US regions, and every sandbox is deleted 1 hour after it starts at the latest (limits). Previews for several open pull requests, or a --timeout above one hour, need a paid plan. Lizard Pro is $19 a month with $19 of usage included and runs up to 40 vCPU of sandboxes at once, which is 20 Small sandboxes.

The workflow does not replace your CI or your database. Tests still run in your pipeline; faster GitHub Actions runners or a self-hosted runner are a separate decision. An app that needs Postgres has to start one inside the sandbox or point at a shared test database.

How do ephemeral environments work for AI coding agents?

For an AI coding agent, an ephemeral environment is a machine per task: create it, give the agent one prompt, read the result, delete it. The pull request pattern creates one environment per change; an agent may want one per attempt, so start time and price per hour matter more than they do for people.

On Lizard that is four commands:

lizard sandbox create -t claude -s small --timeout 900000
lizard sandbox prompt <id> --agent claude "run the tests and fix what fails"
lizard sandbox fork <id> -n 2
lizard sandbox rm <id> --yes

The claude template has Claude Code installed, and prompt runs it on the credentials connected to the sandbox's project. fork starts live copies with the same memory, processes and files, so two attempts can continue from one prepared state. On the trial a fork of a running Small sandbox is refused, because the copy counts as a second Small; parallel forks need a paid plan.

We tested this on 15 November 2026. In a claude sandbox with a failing Python test, the agent read the files, changed a - b to a + b in calc.py, ran the test and finished in about 4 seconds. We sent the prompt through the platform API, which is the call lizard sandbox prompt makes, and checked the CLI flags with --help. Then lizard sandbox fork <id> -n 2 started two copies, and both contained the agent's fix.

Qovery's comparison of ephemeral dev environments for coding agents (30 August 2026) draws the same line: code sandboxes for the agent's inner loop, full application environments per pull request for final verification. For queues of agent tasks, credentials and review of the results, see background coding agents.

FAQ

What is the difference between an ephemeral environment and a preview environment? A preview environment is one kind of ephemeral environment: it exists so a reviewer can open a pull request's changes at a URL. Ephemeral environment is the wider term and also covers test environments and machines for AI coding agents that nobody opens in a browser.

How long does an ephemeral environment live? As long as the work it was created for, with a time limit as a safety net. On Lizard a sandbox from the CLI lives 5 minutes unless --timeout sets another deadline, and on the trial at most 1 hour.

How much do ephemeral environments cost? It depends on the approach. On 15 November 2026 a 2 vCPU sandbox on Lizard cost $0.0162 an hour billed per second, a 2-core GitHub codespace cost $0.18 an hour plus storage, and an Amazon EKS cluster cost $0.10 an hour before any nodes. An environment that nobody uses still costs money while it runs, so set a time limit.

Do ephemeral environments need Kubernetes? No. Kubernetes fits when a change must run next to many other services. An app that starts with one command on one machine can use a microVM sandbox or a cloud development environment without a cluster.

Are ephemeral environments safe for AI-generated code? Safer than a laptop or a shared server, because the environment holds only one task and is deleted afterwards. Isolation varies: Kubernetes namespaces share a kernel across tenants, while a GitHub codespace and a sandbox on Lizard each run in their own virtual machine.

Is GitHub Codespaces an ephemeral environment? It can be used as one. A codespace stops after 30 minutes without activity by default and is deleted after 30 days stopped; set the retention to 0 days and it is deleted when it stops. It is built for a person in an editor more than for a script in CI.

Build with AI. Ship with Lizard.

You don't need a platform team to go live. Your whole cloud, one CLI command away.

Services
—
Add-ons
—
Deployments
—
Sandbox starts
—

We use cookies for essential site functionality and analytics. See our Cookie Policy.