Mastra
Connect a Mastra workspace to an E2B sandbox. With @mastra/e2b, the commands your Mastra agent runs execute in an isolated cloud sandbox instead of on your machine.
- Mastra
- Mastra workspace sandbox
- @mastra/e2b
- TypeScript
Get started
Paste the prompt into your coding agent, or follow the steps yourself.
Paste this into your coding agent
Add E2B sandboxes to this Mastra project.
- 1.Install @mastra/core and @mastra/e2b using the project's package manager.
- 2.The sandbox needs the E2B_API_KEY environment variable. If it isn't set, ask me for my API key from https://console.e2b.dev/?tab=keys. Never hardcode it.
- 3.Follow the Mastra guide at https://docs.e2b.dev/agents/mastra. Give my agent a Workspace with an E2BSandbox, call workspace.init() before it runs, and workspace.destroy() in a finally block.
- 4.Run one task and show me the output that came from the sandbox.
Or set it up yourself
1. Install Mastra and the E2B provider
2. Set your API keys
3. Give the agent a sandbox workspace
4. Run the agent
What runs in the sandbox
Your Mastra agent runs locally; the commands it chooses run in an isolated sandbox.
- execute_command calls from the agent, routed by @mastra/e2b to E2B command execution.
- A sandbox-only workspace has no read_file or write_file tools, so the agent works on files through the shell.
- workspace.init() creates or reconnects the sandbox and workspace.destroy() kills it. timeout is in milliseconds.
- Pass a template ID or name to E2BSandbox to preinstall runtimes and dependencies.
More agent frameworks
Other frameworks that run their tools on E2B.
