🛠 This page is for engineering teams self-hosting their own Lightdash instance. On Lightdash Cloud, sandboxes are fully managed for you — there’s nothing to configure.
What sandboxes are for
Some Lightdash features use an AI agent (Claude Code) that writes and runs code on your behalf. Today that’s:- AI writeback — the agent edits your dbt project (e.g. adds a metric or dimension),
runs
lightdash compileto validate it, and opens a pull request. - Data app generation — the agent generates and builds a small web app from a prompt.
Sandbox providers
The sandbox backend is pluggable. Lightdash talks to a provider-neutral interface, so the same feature code runs on whichever backend your deployment is configured for. You select the provider with theSANDBOX_PROVIDER environment variable.
E2B, AWS Lambda MicroVMs, and Azure Container Apps Sandboxes are all supported
production backends. E2B is the managed default; the AWS and Azure providers are for teams
who want sandboxes to run inside their own cloud account. More providers (Kubernetes, ECS)
are planned.
E2B (production default)
E2B runs each sandbox as a Firecracker microVM in E2B’s cloud. It’s the default — if you don’t setSANDBOX_PROVIDER, Lightdash uses E2B.
To use it you need an E2B account and API key, and the agent needs an Anthropic API key:
AWS Lambda MicroVMs (self-hosted production)
AWS Lambda MicroVMs run each sandbox as a Firecracker microVM inside your own AWS account, so untrusted agent code and your repository contents never leave your infrastructure. The microVMs have no public IP — your backend reaches each one through an AWS-managed endpoint that requires a short-lived per-microVM token — and you control their outbound network access (see Networking and IAM). This is the recommended sandbox provider for customers deploying Lightdash on AWS — it keeps the sandbox boundary inside your existing AWS account and avoids sending agent workloads or repository contents to a third-party service.Prerequisites
Provision these with your own IaC, in the same AWS account and region your Lightdash backend already runs in:- Two MicroVM images — one for data app generation and one for AI writeback (they
bundle different toolchains). Build them from the Dockerfiles in the Lightdash repo
(
sandboxes/data-apps/,sandboxes/ai-writeback/, and the exec agent insandboxes/microvm-agent/), push them to ECR, and register each as a Lambda MicroVM image on the AWS-managedal2023base —ARM_64, 4 GB memory, with the agent’s/readyhook on port 8080. Each registration returns an image ARN for the config below. - Control-plane permissions on your backend’s existing IAM role — add
RunMicrovm,GetMicrovm,SuspendMicrovm,ResumeMicrovm,TerminateMicrovm, andCreateMicrovmAuthToken.
Registering an image uses AWS’s
create-microvm-image, which needs a build role (trusting
lambda.amazonaws.com) and an S3 location to stage the build context. These are
build-time only — not the S3 bucket Lightdash already uses for results and snapshots,
and the backend never touches them at runtime.Configure the provider
Networking and IAM
Override these to tighten the network boundary or to give the microVM an IAM role:Azure Container Apps Sandboxes (self-hosted production)
Azure Container Apps Sandboxes run each sandbox as an isolated, microVM-class environment inside your own Azure subscription, so untrusted agent code and your repository contents never leave your infrastructure. Sandboxes have native suspend/resume (a full memory + disk snapshot with sub-second restore), which is what keeps multi-turn agent conversations fast. This is the recommended sandbox provider for customers deploying Lightdash on Azure — it keeps the sandbox boundary inside your existing Azure tenant and avoids sending agent workloads or repository contents to a third-party service.Azure Container Apps Sandboxes is currently an Azure preview feature. It requires a
Microsoft Entra ID account (personal Microsoft accounts aren’t supported), and its API
surface may change while in preview.
Prerequisites
Provision these in the same Azure subscription and region your Lightdash backend runs in, using theaca CLI or the
Sandboxes portal:
- A sandbox group per feature — one for data app generation and one for AI writeback
(they bundle different toolchains). A sandbox group (
Microsoft.App/SandboxGroups) is the management boundary that holds a feature’s sandboxes and disk image. Give each group a Memory-mode auto-suspend lifecycle policy so idle sandboxes snapshot and scale to zero. - A disk image per group — build the two images from the Dockerfiles in the Lightdash
repo (
sandboxes/data-apps/,sandboxes/ai-writeback/), push them to a container registry (e.g. Azure Container Registry), and register each as a disk image in its sandbox group. Registration returns a disk image ID for the config below. (Unlike the AWS provider, there is no in-VM agent to build — Sandboxes expose a native command/file API.) - A workload identity with the data-plane role — grant your backend’s managed identity
the Container Apps SandboxGroup Data Owner role on each sandbox group. Lightdash uses
DefaultAzureCredential(workload identity on AKS, or the standard Azure credential chain) to authenticate — no client secret is configured here.
Configure the provider
Google Cloud Run Sandboxes (self-hosted, preview)
Use thegcp-cloud-run provider to run data app sandboxes in a
Cloud Run service. Lightdash
connects to the service through an HTTP gateway included in the sandbox image.
Cloud Run Sandboxes is in public preview and currently supports data app generation only.
AI writeback is not supported.
Prerequisites
- A Google Cloud project with billing enabled.
- A recent version of the
gcloudCLI that supportsgcloud beta run deploy --sandbox-launcher. - A checkout of the Lightdash repository.
- External object storage configured for Lightdash.
- An Anthropic API key.
1. Enable the Google Cloud APIs
2. Build the gateway image
From the root of the Lightdash repository, run:3. Deploy the gateway
Generate a shared secret and deploy the image:SANDBOX_SECRET securely. You need the same value when configuring Lightdash.
Although the Cloud Run service allows unauthenticated requests, the gateway requires this
secret for every sandbox operation.
Keep the service at one instance. Active sandboxes run inside that instance and are lost
if Cloud Run replaces it during a generation.
4. Configure Lightdash
Get the gateway URL:5. Restrict sandbox egress (recommended)
Sandbox traffic exits through the gateway instance’s network path, so it follows the service’s VPC egress setting and can be filtered with standard VPC networking. None of this is provisioned by Lightdash — you configure it yourself:- A subnet on the VPC network you’ll filter, in the same region as the gateway service.
-
A Cloud Router and Cloud NAT on that network. Once the service routes all traffic
through the VPC, outbound internet access only works via NAT — without it, sandboxes
and the gateway itself lose all egress. Reserve a static IP for the NAT if you want
a stable egress IP to allowlist on your side (for example, on your git host):
-
Direct VPC egress on the gateway service. This deploys a new revision, so any
active sandboxes are lost — do it while no generation is running:
All sandbox traffic now leaves through your VPC: its public egress IP is the NAT IP, and VPC firewall egress rules apply to it — a deny rule for a destination range blocks matching sandbox traffic while the rest keeps flowing.
-
Filter what sandboxes can reach. VPC firewall rules give you IP/CIDR-level
control. For a domain-level allowlist, add
Secure Web Proxy: create a
deny-all-egress firewall rule that only allows traffic to the proxy, and allowlist the
domains the sandboxes and the gateway need — at minimum
api.anthropic.com,registry.npmjs.org, and your object storage endpoint. Secure Web Proxy is an explicit proxy: clients must be configured to use it (bake proxy settings into the gateway image — sandboxes share its root filesystem), and the deny-all firewall drops anything that bypasses it.
Local Docker provider (development)
For local development you can run sandboxes as plain Docker containers on your own machine — no E2B account required. This is the recommended way to work on or try the AI features locally. It uses the same images E2B builds, but as plain local Docker images. Two separate images are used (different toolchains), mirroring the two E2B templates:Prerequisites
- Docker running locally, with the daemon reachable from the Lightdash backend.
- S3-compatible object storage configured (locally this is MinIO). Suspended-sandbox snapshots are tarred to object storage so a conversation survives the container being destroyed — see external object storage.
- An Anthropic API key (
ANTHROPIC_API_KEY) for the agent.
Setup
-
Build the local sandbox images (each builds from
sandboxes/<feature>/):These are large (the writeback image bundles dbt, the Lightdash CLI and Claude Code) and only need rebuilding when the sandbox toolchain changes. -
Point Lightdash at the Docker provider:
-
Restart the backend and the scheduler so both pick up the new environment. Data app
generation runs in the scheduler worker, so a stale
SANDBOX_PROVIDERthere will keep it on E2B. (With PM2, a plainrestartreuses the cached env — delete and re-start the processes, or restart with--update-env, to actually reload the env file.)
Snapshot lifecycle
Every turn suspends its own sandbox, so in steady state nothing sits idle. Two timers configure the cloud-side idle policy as a backstop — when to auto-suspend a sandbox left running and when to auto-terminate a suspended one:SANDBOX_IDLE_TIMEOUT_MS feeds the auto-suspend policy on both the Lambda MicroVMs and
Azure Sandboxes providers (for Azure it sets each sandbox’s Memory-mode auto-suspend
interval). SANDBOX_SNAPSHOT_RETENTION_MS is read only by Lambda MicroVMs — on Azure,
suspended-sandbox retention is governed by the sandbox group’s own auto-delete policy.
E2B manages idle sandboxes itself, and the Docker and Cloud Run providers have
no cloud-side idle handling — both persist suspend-time snapshots to object storage and
destroy the sandbox, so nothing idles in the first place.