Blaxel
Executes commands in isolated Blaxel cloud sandboxes. Provides secure, isolated code execution environments with support for mounting cloud storage (S3, GCS) via FUSE. For interface details, see WorkspaceSandbox interface.
InstallationInstallation的直接链接
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/blaxel
pnpm add @mastra/blaxel
yarn add @mastra/blaxel
bun add @mastra/blaxel
UsageUsage的直接链接
Add a BlaxelSandbox to a workspace and assign it to an agent:
import { Agent } from '@mastra/core/agent'
import { Workspace } from '@mastra/core/workspace'
import { BlaxelSandbox } from '@mastra/blaxel'
const workspace = new Workspace({
sandbox: new BlaxelSandbox(),
})
const agent = new Agent({
id: 'code-agent',
name: 'Code Agent',
instructions: 'You are a coding assistant working in this workspace.',
model: 'anthropic/claude-sonnet-4-6',
workspace,
})
Custom image with resourcesCustom image with resources的直接链接
Use a custom Docker image with additional memory:
const workspace = new Workspace({
sandbox: new BlaxelSandbox({
image: 'node:20-slim',
memory: 8192,
region: 'auto',
timeout: '10m',
}),
})
Constructor parametersConstructor parameters的直接链接
id?:
image?:
memory?:
timeout?:
region?:
env?:
workingDirectory?:
cwd is given. A per-command cwd always wins. Use an absolute path.labels?:
runtimes?:
ports?:
PropertiesProperties的直接链接
id:
name:
provider:
status:
instance:
processes:
Background processesBackground processes的直接链接
BlaxelSandbox includes a built-in process manager for spawning and managing background processes.
const sandbox = new BlaxelSandbox({ id: 'dev-sandbox' })
await sandbox.start()
// Spawn a background process
const handle = await sandbox.processes.spawn('node server.js', {
env: { PORT: '3000' },
onStdout: data => console.log(data),
})
// Interact with the process
await handle.sendStdin('hello\n')
await handle.closeStdin()
console.log(handle.stdout)
await handle.kill()
Spawned processes have a writable stdin by default. Pass stdinMode: 'ignore' to start a process with stdin closed so commands that read stdin get EOF immediately.
See SandboxProcessManager reference for the full API.
Mounting cloud storageMounting cloud storage的直接链接
Blaxel sandboxes can mount S3 or GCS filesystems, making cloud storage accessible as a local directory inside the sandbox.
S3S3的直接链接
import { Workspace } from '@mastra/core/workspace'
import { S3Filesystem } from '@mastra/s3'
import { BlaxelSandbox } from '@mastra/blaxel'
const workspace = new Workspace({
mounts: {
'/data': new S3Filesystem({
bucket: 'my-bucket',
region: 'us-east-1',
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
}),
},
sandbox: new BlaxelSandbox(),
})
GCSGCS的直接链接
import { Workspace } from '@mastra/core/workspace'
import { GCSFilesystem } from '@mastra/gcs'
import { BlaxelSandbox } from '@mastra/blaxel'
const workspace = new Workspace({
mounts: {
'/data': new GCSFilesystem({
bucket: 'my-bucket',
credentials: JSON.parse(process.env.GCS_SERVICE_ACCOUNT_KEY!),
}),
},
sandbox: new BlaxelSandbox(),
})