Skip to content
Sandbox SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

Mastra

Give a Mastra agent a sandbox on E2B, Daytona, Vercel Sandbox or Docker with sandboxTools from @opencoredev/sandbox-sdk/mastra. How it differs from Workspace.

sandboxTools(box) from @opencoredev/sandbox-sdk/mastra returns a Mastra tool map. Pass it as tools to new Agent and the agent can run commands, read and edit files, and start dev servers in the sandbox.

Mastra also has its own sandbox API: a Workspace from @mastra/core/workspace with a sandbox such as LocalSandbox, passed to new Agent as workspace. sandboxTools takes the other route. The sandbox comes from createSandbox and the tools go in tools, so the same agent code runs on E2B, Daytona, Vercel Sandbox, Docker on your own machine through local(), and the other providers. Switching providers changes the import, the factory call and any options that provider needs, such as ports for a dev server on Vercel Sandbox, but not the agent. A tool or option the provider can’t support fails with unsupported: agentOS, for example, has no SDK background processes, so start_process fails there. Capabilities lists what each provider supports.

For the tools themselves and how to limit them, see Give your agent a sandbox.

Install

npm install @opencoredev/sandbox-sdk @mastra/core zod
pnpm add @opencoredev/sandbox-sdk @mastra/core zod
yarn add @opencoredev/sandbox-sdk @mastra/core zod
bun add @opencoredev/sandbox-sdk @mastra/core zod

Needs Mastra 1.78 and Zod 4.6. Some cloud providers also need their own SDK; Install lists them.

Run an agent

import { Agent } from "@mastra/core/agent";
import { createSandbox } from "@opencoredev/sandbox-sdk";
import { e2b } from "@opencoredev/sandbox-sdk/e2b";
import { sandboxTools } from "@opencoredev/sandbox-sdk/mastra";

await using box = await createSandbox(e2b());

const coder = new Agent({
  id: "coder",
  name: "Coder",
  instructions: "You work inside a Linux sandbox. Verify every change by running it.",
  model: "anthropic/claude-opus-5-5",
  tools: sandboxTools(box),
});

const result = await coder.generate(
  "Create a Vite React app in /workspace/app and start it on port 5173.",
);
console.log(result.text);

The agent writes the app, runs npm install, and starts the dev server with start_process, which waits until the port answers and returns its URL. result.text holds the agent’s final answer.

Limit the tools

The same options work on every framework. This agent can only read and search:

import { Agent } from "@mastra/core/agent";
import { createSandbox } from "@opencoredev/sandbox-sdk";
import { local } from "@opencoredev/sandbox-sdk/local";
import { sandboxTools } from "@opencoredev/sandbox-sdk/mastra";

await using box = await createSandbox(local(), { network: "none" });

const reviewer = new Agent({
  id: "reviewer",
  name: "Reviewer",
  instructions: "Read the code in /workspace and report problems. Do not change files.",
  model: "anthropic/claude-opus-5-5",
  tools: sandboxTools(box, { allow: ["read_file", "search", "list_files"] }),
});

search and list_files are optional tools, so allow turns them on. The full option list is in Agent tools.

What Mastra gets

Each tool has an id, a description that tells the model when not to use it, a Zod input schema, and an output of { text }. The model sees text through toModelOutput: a verdict line and capped output. Aborting the agent run aborts the command inside the sandbox too.

Was this page helpful?