VercelServerlessSandbox
以 Vercel 無伺服器函數的形式執行指令。提供全球分佈、自動擴展且毋須管理基礎架構的執行環境。如需介面詳情,請參閱 WorkspaceSandbox 介面。
注意
VercelServerlessSandbox 不保留狀態。它不提供持久檔案系統、互動式 shell 或長時間運行的背景程序。只有 /tmp 可供寫入,而且每次調用之間的內容都是暫時的。
備註
如需具備持久檔案系統、sudo 存取權、公開連接埠及背景程序的完整 Linux MicroVM,請使用由 Vercel Sandbox 產品支援的 VercelSandbox。
安裝安裝 的直接連結
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/vercel
pnpm add @mastra/vercel
yarn add @mastra/vercel
bun add @mastra/vercel
使用方式使用方式 的直接連結
將 VercelServerlessSandbox 加入 Workspace,並將其指派給 Agent:
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,
})
使用自訂資源的團隊範圍部署使用自訂資源的團隊範圍部署 的直接連結
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[]
= ['iad1']
部署區域。
maxDuration?:
number
= 60
函數的最長持續時間(秒)。
memory?:
number
= 1024
函數記憶體(MB)。
env?:
Record<string, string>
內嵌於已部署函數原始碼的環境變數。這些變數在部署時嵌入,而非動態設定。
commandTimeout?:
number
= 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 介面
- Workspace 類別
- E2BSandbox:具備持久檔案系統及程序管理功能的完整雲端 Sandbox