WorkspaceSandbox
Added in: @mastra/core@1.1.0
The WorkspaceSandbox interface defines how workspaces execute commands.
MethodsDirect link to Methods
start()Direct link to start
Start the sandbox. Called automatically by workspace.init() or on first executeCommand() call.
await sandbox.start();
This method prepares the sandbox for command execution.
stop()Direct link to stop
Stop the sandbox.
await sandbox.stop?.();
destroy()Direct link to destroy
Clean up sandbox resources. Called by workspace.destroy().
await sandbox.destroy();
executeCommand(command, args?, options?)Direct link to executecommandcommand-args-options
Execute a shell command.
const result = await sandbox.executeCommand('ls', ['-la', '/docs']);
const result = await sandbox.executeCommand('npm', ['install', 'lodash']);
Parameters:
command:
string
Command to execute
args?:
string[]
Command arguments
options.timeout?:
number
Execution timeout in milliseconds
options.cwd?:
string
Working directory for the command
options.env?:
Record<string, string>
Additional environment variables
options.onStdout?:
(data: string) => void
Callback for stdout streaming
options.onStderr?:
(data: string) => void
Callback for stderr streaming
getInfo()Direct link to getinfo
Get sandbox status and resource information.
const info = await sandbox.getInfo();
// { status: 'running', resources: { memoryMB: 512, cpuPercent: 5 } }
getInstructions()Direct link to getinstructions
Get a description of how this sandbox works. Used in tool descriptions to help agents understand the execution context.
const instructions = sandbox.getInstructions?.();
// 'Local command execution. Working directory: "/workspace".'