> Discover all available pages from the documentation index: https://mastra.zisheng.pro/llms.txt # SandboxProvider `SandboxProvider` 是包用来向 [`MastraEditor`](https://mastra.zisheng.pro/reference/editor/mastra-editor) 注册 Sandbox 的接口。Editor 会在 Workspace 实例化时调用 `createSandbox(config)`,并使用已存储 [`StorageWorkspaceRef`](https://mastra.zisheng.pro/reference/editor/storage-workspace-ref) Sandbox 配置中的 `provider` id 作为查找键。 内置 `local` Sandbox Provider 会自动注册。外部 Provider(例如 E2B)通过 `MastraEditorConfig.sandboxes` 提供。 ## 使用示例 ```typescript import { MastraEditor } from '@mastra/editor' import { e2bSandboxProvider } from '@mastra/e2b' new MastraEditor({ sandboxes: { [e2bSandboxProvider.id]: e2bSandboxProvider, }, }) ``` ## 属性 **id** (`string`): 唯一的 Provider 标识符(例如 "local"、"e2b")。必须与使用此 Provider 的每个已存储 Workspace 上的 StorageSandboxConfig.provider 一致。 **name** (`string`): 在 UI 中显示的易读名称。 **description** (`string`): Workspace Sandbox 选择器中显示的简短描述。 **configSchema** (`Record`): 描述 Provider 专用配置的 JSON Schema。UI 使用它渲染配置表单。 **createSandbox** (`(config: TConfig) => WorkspaceSandbox | Promise`): 根据已存储配置创建运行时 WorkspaceSandbox 实例。在 Workspace 实例化时调用。 ## 实现 Provider ```typescript 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 { return createMySandbox({ apiKey: config.apiKey }) }, } ``` 注册后,管理员可以从内联 Workspace 配置或已存储的 [`StorageWorkspaceRef`](https://mastra.zisheng.pro/reference/editor/storage-workspace-ref) 中引用该 Provider。 ## 相关内容 - [Workspace](https://agent-builder.mastra.ai/workspace):概念和完整示例。 - [StorageWorkspaceRef](https://mastra.zisheng.pro/reference/editor/storage-workspace-ref):由 `createSandbox` 使用的已存储配置。 - [FilesystemProvider](https://mastra.zisheng.pro/reference/editor/filesystem-provider):用于文件访问的同级 Provider。 - [MastraEditor 类](https://mastra.zisheng.pro/reference/editor/mastra-editor):Provider 注册表。