You can now deploy your Mastra project (Server and Studio) to an ephemeral sandbox — manually or programmatically, with configurable runtime limits. Share previews with teammates, let agents deploy autonomously to verify results, or run per-user instances isolated from your infrastructure.
A sandbox deploy gives you two public URLs to test your application. Open Studio to chat with your agents, or hit /api to test the endpoints directly.
We're starting today with E2B, Daytona, and Vercel Sandbox, with more providers to follow.
Before sandbox deployments, hosting a Mastra project meant working through the full development lifecycle — create a PR, push a deploy, share a link. Now you can skip the pipeline and deploy straight to a sandbox. Subsequent deployments reconnect to the existing sandbox without reinstalling dependencies.
Each deployment writes a sandbox-deployment.json manifest with sandbox url, id, and expiresAt, so CI can smoke-test the deploy.
Get started
Install the deployer and a sandbox provider. The examples below use E2B:
npm install @mastra/deployer-sandbox @mastra/e2b@mastra/core@1.52.0 or later, added in PR #19577.Configure SandboxDeployer on the Mastra instance. The id identifies the sandbox — repeat deploys with the same id reconnect to the existing one instead of provisioning a fresh sandbox:
import { Mastra } from "@mastra/core/mastra";
import { SandboxDeployer } from "@mastra/deployer-sandbox";
import { E2BSandbox } from "@mastra/e2b";
export const mastra = new Mastra({
// ...
deployer: new SandboxDeployer({
sandbox: new E2BSandbox({
id: "mastra-sandbox-deploy",
template: "base",
timeout: 3_600_000 // 1 hour
})
})
});Manually deploy
Add your E2B API key to .env:
E2B_API_KEY=e2b_...mastra build doesn't auto-load .env, and the deployer needs your provider credentials at build time. Install dotenv-cli and wire up a deploy script that loads .env before running the build:
npm install -D dotenv-cli{
"scripts": {
"deploy": "dotenv -e .env -- mastra build"
}
}Then build and deploy in one command:
npm run deployEach deploy outputs two URLs to the terminal and writes a manifest into .mastra/output:
- API endpoints: https://4111-eijrptonwfyfew4q7cnl6.e2b.app/api
- Studio: https://4111-eijrptonwfyfew4q7cnl6.e2b.app
{
"provider": "e2b",
"sandboxId": "mastra-sandbox-deploy",
"url": "https://4111-eijrptonwfyfew4q7cnl6.e2b.app",
"port": 4111,
"deployedAt": "2026-08-04T12:46:50.675Z",
"expiresAt": "2026-08-04T13:46:50.675Z"
}Hit API endpoints by appending /api to the sandbox url:
curl -s -X POST <sandbox-url>/api/agents/weatherAgent/generate \
-H "Content-Type: application/json" \
-d '{"messages":[{"role":"user","content":"Weather in London"}]}' \
| jq -r '.text'Programmatically deploy
From CI, agent code, or your own scripts, use deployToSandbox() to deploy. By default this is API only — pass studio: true to include Studio:
import { deployToSandbox } from "@mastra/deployer-sandbox";
import { E2BSandbox } from "@mastra/e2b";
const deployment = await deployToSandbox({
sandbox: new E2BSandbox({
id: "ci-smoke",
template: "base",
timeout: 3_600_000 // 1 hour
}),
dir: ".mastra/output",
studio: true // optional
});Use deployment.stop(), and deployment.destroy() for further control over the sandbox lifecycle.
For more information and full configuration options, see:
