WBX Sandbox
Integrations

Mastra

Give a Mastra agent its own Linux computer: the workspace tools – commands, background processes, files – run in a WBX sandbox, an isolated microVM where the agent is root. One package, one line in the workspace.

Install

npm install @wbx-sandbox/mastra @mastra/core
export WBXSANDBOX_API_KEY=YOUR_API_KEY        # API keys in the portal

Works with @mastra/core 1.80 and newer (1.x) and Node.js 22.13+. The package uses the TypeScript SDK for every call.

Quickstart

import { Agent } from '@mastra/core/agent'
import { Workspace } from '@mastra/core/workspace'
import { WBXSandbox } from '@wbx-sandbox/mastra'

const workspace = new Workspace({
  sandbox: new WBXSandbox({ id: 'my-project', template: 'code-interpreter' }),
})

export const agent = new Agent({
  id: 'code-agent',
  name: 'Code Agent',
  instructions: 'You write and run code in your sandbox.',
  model: 'openai/gpt-5-mini',
  workspace,
})

The agent gets Mastra's workspace tools and they run in the sandbox. The id is the sandbox name: the next start with the same id continues in the same sandbox, with its files.

What happens when

MastraWBX Sandbox
start()Gets the sandbox named id, or creates it. A sleeping sandbox wakes up in a few seconds.
stop()Stops background processes started by the agent and puts the sandbox to sleep – files kept, no running cost.
destroy()Deletes the sandbox with its files.
snapshot()With checkpointName: saves the disk as a snapshot; a new sandbox with that checkpoint starts from it.
networking.getPortUrl(port)The public HTTPS address of a port, with its access token.
computerWith the desktop template: Mastra's computer tools (screenshot, mouse, keyboard) on the sandbox desktop.

Options

OptionDefaultMeaning
idrandom mastra-…Sandbox name: lower-case letters, digits, . _ -. The same id reconnects.
sandboxId–Attach to an existing sandbox by its ID (sb_…)
template"base"Base image – see Templates
computeClassaccount defaultCompute class
networkfull internet{ mode: "allowlist", allow: [...] }, { mode: "none" }, ip: "dual" – see Network
lifetimeSeconds3600After this the sandbox falls asleep (files kept)
idleTimeoutSeconds–Fall asleep after this many seconds without commands
keepDaysplan defaultHow long a sleeping sandbox keeps its files
timeout300000Default command timeout in milliseconds
env–Environment for every command (change it with setEnv())
onStopBehavior"sleep""keep" leaves the sandbox running on stop()
checkpointName–Name of the snapshot that snapshot() saves and a new sandbox starts from
apiKey, baseURLfrom the environmentWBXSANDBOX_API_KEY / WBXSANDBOX_URL

Use the sandbox directly

const sandbox = new WBXSandbox({ id: 'my-project' })
await sandbox.start()
const r = await sandbox.executeCommand('python3', ['-c', 'print(6 * 7)'])
console.log(r.stdout)                                  // 42

await sandbox.processes.spawn('python3 -m http.server 8000')
console.log(await sandbox.networking.getPortUrl(8000))  // open in a browser

A browser keeps the port's access token as a cookie; a script sends it as the X-WBX-Token header. The app must listen on 0.0.0.0.

Good to know

  • Commands run with /bin/sh -c as root in /home/user; a non-zero exit code is a normal result for the agent, not an error.
  • The desktop is available to paying customers. The API does not report the mouse position, so getCursorPosition() returns where the agent last moved the mouse.
  • Mounting S3 or GCS into the sandbox is not supported yet – copy the data in with writeFiles().
  • For MastraEditor, register wbxSandboxProvider (provider id wbx).

Examples (fix failing tests, CSV to chart) and source: github.com/WBX-Sandbox/mastra · package: npmjs.com/package/@wbx-sandbox/mastra.

Next steps