Skip to main content

SandboxProvider

SandboxProvider is the interface a package implements to register a sandbox with MastraEditor. The editor calls createSandbox(config) at workspace hydration time, using the provider id from the stored StorageWorkspaceRef sandbox config as the lookup key.

The built-in local sandbox provider is auto-registered. External providers (for example, E2B) are supplied via MastraEditorConfig.sandboxes.

Usage example
Direct link to Usage example

src/mastra/index.ts
import { MastraEditor } from '@mastra/editor'
import { e2bSandboxProvider } from '@mastra/e2b'

new MastraEditor({
sandboxes: {
[e2bSandboxProvider.id]: e2bSandboxProvider,
},
})

Properties
Direct link to Properties

id:

string
Unique provider identifier (for example, `"local"`, `"e2b"`). Must match `StorageSandboxConfig.provider` on every stored workspace that uses this provider.

name:

string
Human-readable name for UI display.

description?:

string
Short description shown in the workspace sandbox picker.

configSchema?:

Record<string, unknown>
JSON Schema describing provider-specific configuration. Used by the UI to render config forms.

createSandbox:

(config: TConfig) => WorkspaceSandbox | Promise<WorkspaceSandbox>
Create a runtime `WorkspaceSandbox` instance from the stored config. Called at workspace hydration time.

Implementing a provider
Direct link to Implementing a provider

src/providers/my-sandbox.ts
import type { SandboxProvider, WorkspaceSandbox } from '@mastra/core/editor'

export const mySandboxProvider: SandboxProvider<{ apiKey: string }> = {
id: 'my-sandbox',
name: 'My Sandbox',
description: 'Cloud sandbox for command execution.',
configSchema: {
type: 'object',
required: ['apiKey'],
properties: {
apiKey: { type: 'string' },
},
},
async createSandbox(config): Promise<WorkspaceSandbox> {
return createMySandbox({ apiKey: config.apiKey })
},
}

Once registered, admins can reference the provider from an inline workspace config or a stored StorageWorkspaceRef.

On this page