> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # VercelServerlessSandbox 以 [Vercel](https://vercel.com) 無伺服器函數的形式執行指令。提供全球分佈、自動擴展且毋須管理基礎架構的執行環境。如需介面詳情,請參閱 [WorkspaceSandbox 介面](https://mastra.zisheng.pro/zh-HK/reference/workspace/sandbox)。 > **注意:** VercelServerlessSandbox 不保留狀態。它不提供持久檔案系統、互動式 shell 或長時間運行的背景程序。只有 `/tmp` 可供寫入,而且每次調用之間的內容都是暫時的。 > **備註:** 如需具備持久檔案系統、`sudo` 存取權、公開連接埠及背景程序的完整 Linux MicroVM,請使用由 [Vercel Sandbox](https://vercel.com/docs/vercel-sandbox) 產品支援的 [`VercelSandbox`](https://mastra.zisheng.pro/zh-HK/reference/workspace/vercel-sandbox)。 ## 安裝 **npm**: ```bash npm install @mastra/vercel ``` **pnpm**: ```bash pnpm add @mastra/vercel ``` **Yarn**: ```bash yarn add @mastra/vercel ``` **Bun**: ```bash bun add @mastra/vercel ``` ## 使用方式 將 `VercelServerlessSandbox` 加入 Workspace,並將其指派給 Agent: ```typescript import { Agent } from '@mastra/core/agent' import { Workspace } from '@mastra/core/workspace' import { VercelServerlessSandbox } from '@mastra/vercel' const workspace = new Workspace({ sandbox: new VercelServerlessSandbox({ token: process.env.VERCEL_TOKEN, }), }) const agent = new Agent({ id: 'dev-agent', name: 'dev-agent', instructions: 'You are a coding assistant working in this workspace.', model: 'anthropic/claude-sonnet-4-6', workspace, }) ``` ### 使用自訂資源的團隊範圍部署 ```typescript const workspace = new Workspace({ sandbox: new VercelServerlessSandbox({ token: process.env.VERCEL_TOKEN, teamId: 'team_abc123', regions: ['iad1', 'sfo1'], maxDuration: 120, memory: 3008, env: { NODE_ENV: 'production', }, }), }) ``` ## 建構函數參數 **token** (`string`): Vercel API token。未提供時會改用 VERCEL\_TOKEN 環境變數。 **teamId** (`string`): 用於團隊範圍部署的 Vercel 團隊 ID。 **projectName** (`string`): 現有 Vercel 項目名稱。如省略,系統會自動產生。 **regions** (`string[]`): 部署區域。 (Default: `['iad1']`) **maxDuration** (`number`): 函數的最長持續時間(秒)。 (Default: `60`) **memory** (`number`): 函數記憶體(MB)。 (Default: `1024`) **env** (`Record`): 內嵌於已部署函數原始碼的環境變數。這些變數在部署時嵌入,而非動態設定。 **commandTimeout** (`number`): 每次調用的指令逾時時間(毫秒)。 (Default: `55000`) **instructions** (`string | ((opts) => string)`): 自訂指示,用以覆寫 getInstructions() 傳回的預設指示。傳入字串可完全取代預設指示,亦可傳入函數以擴充預設內容。 **onStart** (`SandboxLifecycleHook`): Sandbox 達到 running 狀態後呼叫的生命週期 hook。 **onStop** (`SandboxLifecycleHook`): Sandbox 停止前呼叫的生命週期 hook。 **onDestroy** (`SandboxLifecycleHook`): Sandbox 銷毀前呼叫的生命週期 hook。 ## 屬性 **id** (`string`): 此 Sandbox 實例的唯一識別碼。 **name** (`'VercelServerlessSandbox'`): 方便閱讀的名稱。 **provider** (`'vercel-serverless'`): Provider 類型識別碼。 **status** (`ProviderStatus`): 目前的生命週期狀態:'pending'、'starting'、'running'、'stopping'、'stopped'、'destroying'、'destroyed' 或 'error'。 ## 限制 VercelServerlessSandbox 在底層使用無伺服器函數,這表示: - **沒有持久檔案系統**:寫入 `/tmp` 的檔案是暫時的,並會在每次調用之間清除。 - **沒有互動式 shell**:指令透過 `/bin/sh -c` 執行,不支援 stdin 串流。 - **沒有背景程序**:不提供程序管理器、PID 或長時間運行的工作。 - **不支援掛載**:不支援掛載雲端儲存空間(S3、GCS)。 - **逾時限制**:最長執行時間受 `maxDuration` 限制(預設為 60 秒)。 ## 相關內容 - [WorkspaceSandbox 介面](https://mastra.zisheng.pro/zh-HK/reference/workspace/sandbox) - [Workspace 類別](https://mastra.zisheng.pro/zh-HK/reference/workspace/workspace-class) - [E2BSandbox](https://mastra.zisheng.pro/zh-HK/reference/workspace/e2b-sandbox):具備持久檔案系統及程序管理功能的完整雲端 Sandbox