> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # SandboxProvider `SandboxProvider` 是套件用來向 [`MastraEditor`](https://mastra.zisheng.pro/zh-HK/reference/editor/mastra-editor) 註冊 Sandbox 的介面。Editor 會在 Workspace hydrate 時呼叫 `createSandbox(config)`,並以已儲存 [`StorageWorkspaceRef`](https://mastra.zisheng.pro/zh-HK/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 hydrate 時呼叫。 ## 實作 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 }) }, } ``` 註冊後,管理員可在 inline Workspace 配置或已儲存的 [`StorageWorkspaceRef`](https://mastra.zisheng.pro/zh-HK/reference/editor/storage-workspace-ref) 中引用此 Provider。 ## 相關內容 - [Workspace](https://agent-builder.mastra.ai/workspace):概念及完整範例。 - [StorageWorkspaceRef](https://mastra.zisheng.pro/zh-HK/reference/editor/storage-workspace-ref):`createSandbox` 使用的已儲存配置。 - [FilesystemProvider](https://mastra.zisheng.pro/zh-HK/reference/editor/filesystem-provider):用於檔案存取的同類 Provider。 - [MastraEditor 類別](https://mastra.zisheng.pro/zh-HK/reference/editor/mastra-editor):Provider registry。