Class: MontySandbox
Python-only, deny-by-default sandbox backed by Monty’s selected worker pool.
Extends
Section titled “Extends”MastraSandbox
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new MontySandbox(
options?):MontySandbox
Parameters
Section titled “Parameters”options?
Section titled “options?”MontySandboxOptions = {}
Returns
Section titled “Returns”MontySandbox
Overrides
Section titled “Overrides”MastraSandbox.constructor
Properties
Section titled “Properties”_destroyPromise?
Section titled “_destroyPromise?”
protectedoptional_destroyPromise?:Promise<void>
Promise for _destroy() to prevent race conditions from concurrent calls
Inherited from
Section titled “Inherited from”MastraSandbox._destroyPromise
_startPromise?
Section titled “_startPromise?”
protectedoptional_startPromise?:Promise<void|SandboxStartResult>
Promise for _start() to prevent race conditions from concurrent calls
Inherited from
Section titled “Inherited from”MastraSandbox._startPromise
_stopPromise?
Section titled “_stopPromise?”
protectedoptional_stopPromise?:Promise<void>
Promise for _stop() to prevent race conditions from concurrent calls
Inherited from
Section titled “Inherited from”MastraSandbox._stopPromise
_workingDirectory?
Section titled “_workingDirectory?”
protectedoptional_workingDirectory?:string
Effective default working directory, exposed via the
workingDirectory getter. Protected so providers that compute or
probe their effective value (e.g. a default like /workspace, or a
runtime probe) can write it back with setWorkingDirectory and
keep the getter truthful.
Inherited from
Section titled “Inherited from”MastraSandbox._workingDirectory
component
Section titled “component”component:
RegisteredLogger
Inherited from
Section titled “Inherited from”MastraSandbox.component
computer?
Section titled “computer?”
readonlyoptionalcomputer?:SandboxComputer
Optional computer-use (desktop) capability - implement to enable workspace computer tools
Inherited from
Section titled “Inherited from”MastraSandbox.computer
readonlyid:string
Unique identifier for this sandbox instance
Overrides
Section titled “Overrides”MastraSandbox.id
logger
Section titled “logger”
protectedlogger:IMastraLogger
Inherited from
Section titled “Inherited from”MastraSandbox.logger
mounts?
Section titled “mounts?”
readonlyoptionalmounts?:MountManager
Mount manager - automatically created if subclass implements mount()
Inherited from
Section titled “Inherited from”MastraSandbox.mounts
readonlyname:string
Human-readable name (e.g., ‘E2B Sandbox’, ‘Docker’)
Overrides
Section titled “Overrides”MastraSandbox.name
networking?
Section titled “networking?”
readonlyoptionalnetworking?:SandboxNetworking
Optional networking capability - implement to expose public port URLs
Inherited from
Section titled “Inherited from”MastraSandbox.networking
processes?
Section titled “processes?”
readonlyoptionalprocesses?:SandboxProcessManager<MastraSandbox<unknown>>
Process manager
Inherited from
Section titled “Inherited from”MastraSandbox.processes
provider
Section titled “provider”
readonlyprovider:"monty"="monty"
Provider type identifier
Overrides
Section titled “Overrides”MastraSandbox.provider
status
Section titled “status”status:
ProviderStatus="pending"
Current status of the sandbox
Overrides
Section titled “Overrides”MastraSandbox.status
supportsCheckpoints
Section titled “supportsCheckpoints”
readonlysupportsCheckpoints:boolean
Whether snapshot() persists real checkpoints. Providers overriding
snapshot() with a real implementation should also override this to true.
Inherited from
Section titled “Inherited from”MastraSandbox.supportsCheckpoints
Accessors
Section titled “Accessors”workingDirectory
Section titled “workingDirectory”Get Signature
Section titled “Get Signature”get workingDirectory():
string|undefined
The sandbox’s default working directory, when one is configured.
Commands and process spawns without a per-command cwd run here;
per-command cwd always wins. undefined means the provider’s own
default applies (typically the home directory).
Returns
Section titled “Returns”string | undefined
Inherited from
Section titled “Inherited from”MastraSandbox.workingDirectory
Methods
Section titled “Methods”_destroy()
Section titled “_destroy()”_destroy():
Promise<void>
Destroy the sandbox and clean up all resources (wrapper with status management).
This method is race-condition-safe - concurrent calls will return the same promise. Handles status management.
Subclasses override destroy() to provide their destroy logic.
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”MastraSandbox._destroy
_start()
Section titled “_start()”_start(
options?):Promise<void|SandboxStartResult>
Start the sandbox (wrapper with status management and race-condition safety).
This method is race-condition-safe - concurrent calls will return the same promise. Handles status management and automatically processes pending mounts after startup.
Subclasses override start() to provide their startup logic.
Parameters
Section titled “Parameters”options?
Section titled “options?”SandboxStartOptions
Returns
Section titled “Returns”Promise<void | SandboxStartResult>
Inherited from
Section titled “Inherited from”MastraSandbox._start
_stop()
Section titled “_stop()”_stop():
Promise<void>
Stop the sandbox (wrapper with status management and race-condition safety).
This method is race-condition-safe - concurrent calls will return the same promise. Handles status management.
Subclasses override stop() to provide their stop logic.
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”MastraSandbox._stop
connect()?
Section titled “connect()?”
protectedoptionalconnect(handle,options?):void|Promise<void>
Adopt/wake/resume the handle find returned. Throwing fails
start(): a provider that should fall back to creating fresh puts that
policy in find (return undefined for an unusable handle) instead.
Parameters
Section titled “Parameters”handle
Section titled “handle”unknown
options?
Section titled “options?”SandboxStartOptions
Returns
Section titled “Returns”void | Promise<void>
Inherited from
Section titled “Inherited from”MastraSandbox.connect
create()?
Section titled “create()?”
protectedoptionalcreate(options?):void|Promise<void>
Provision a fresh VM/environment for this sandbox’s logical id.
Implementing this without overriding start() opts into base-orchestrated
acquisition, which derives the outcome from the branch that ran: find then
connect reports ‘connected’, create reports ‘created’.
Parameters
Section titled “Parameters”options?
Section titled “options?”SandboxStartOptions
Returns
Section titled “Returns”void | Promise<void>
Inherited from
Section titled “Inherited from”MastraSandbox.create
destroy()
Section titled “destroy()”destroy():
Promise<void>
The process-wide pool stays warm; each command closes its own checkout.
Returns
Section titled “Returns”Promise<void>
Overrides
Section titled “Overrides”MastraSandbox.destroy
ensureRunning()
Section titled “ensureRunning()”ensureRunning():
Promise<void>
Ensure the sandbox is running.
Calls _start() if status is not ‘running’. Useful for lazy initialization
where operations should automatically start the sandbox if needed.
This is the lazy entry point into the id-keyed getOrCreate contract described on start.
Returns
Section titled “Returns”Promise<void>
Throws
Section titled “Throws”if the sandbox fails to reach ‘running’ status
Example
Section titled “Example”async executeCommand(command: string): Promise<CommandResult> { await this.ensureRunning(); // Now safe to use the sandbox}Inherited from
Section titled “Inherited from”MastraSandbox.ensureRunning
executeCommand()
Section titled “executeCommand()”executeCommand(
command,args?,options?):Promise<CommandResult>
Execute Python source and map Monty output to Mastra’s command result.
Parameters
Section titled “Parameters”command
Section titled “command”string
string[] = []
options?
Section titled “options?”ExecuteCommandOptions = {}
Returns
Section titled “Returns”Promise<CommandResult>
Overrides
Section titled “Overrides”MastraSandbox.executeCommand
find()?
Section titled “find()?”
protectedoptionalfind(options?):Promise<unknown>
Locate an existing VM/environment for this sandbox’s logical id. Returns
a provider-native handle for connect to adopt, or undefined when
nothing usable exists. Avoid side effects where the provider’s API allows.
Parameters
Section titled “Parameters”options?
Section titled “options?”SandboxStartOptions
Returns
Section titled “Returns”Promise<unknown>
Inherited from
Section titled “Inherited from”MastraSandbox.find
getEnv()
Section titled “getEnv()”getEnv():
Record<string,string|undefined>
Snapshot of the current runtime environment overlay.
Returns a fresh copy — mutating it never affects the stored overlay; use setEnv to change it. The process manager reads this per spawn to merge the overlay into command environments.
Returns
Section titled “Returns”Record<string, string | undefined>
Inherited from
Section titled “Inherited from”MastraSandbox.getEnv
getInfo()
Section titled “getInfo()”getInfo():
SandboxInfo
Get sandbox status and metadata
Returns
Section titled “Returns”SandboxInfo
Overrides
Section titled “Overrides”MastraSandbox.getInfo
getInstructions()
Section titled “getInstructions()”getInstructions():
string
Get instructions describing how this sandbox works
Returns
Section titled “Returns”string
Overrides
Section titled “Overrides”MastraSandbox.getInstructions
isReady()
Section titled “isReady()”isReady():
Promise<boolean>
Returns
Section titled “Returns”Promise<boolean>
mount()?
Section titled “mount()?”
optionalmount(filesystem,mountPath):Promise<MountResult>
Optional mount method - implement to enable mounting support
Parameters
Section titled “Parameters”filesystem
Section titled “filesystem”WorkspaceFilesystem
mountPath
Section titled “mountPath”string
Returns
Section titled “Returns”Promise<MountResult>
Inherited from
Section titled “Inherited from”MastraSandbox.mount
setEnv()
Section titled “setEnv()”setEnv(
update):void
Update the sandbox’s runtime environment overlay.
The updater receives a copy of the current overlay and returns the new one, so a single call can set, unset, or batch-update variables:
sandbox.setEnv(env => ({ ...env, GH_TOKEN: token }));Changes apply immediately to subsequent commands and processes routed
through the sandbox’s process manager (including the built-in
executeCommand), survive provider pause/resume and VM replacement,
and are never written into the VM — the overlay is merged per spawn,
not persisted. Removing a key removes it from the overlay only;
env values a provider supplies on its own still apply.
Parameters
Section titled “Parameters”update
Section titled “update”(env) => Record<string, string | undefined>
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”MastraSandbox.setEnv
setOnStart()
Section titled “setOnStart()”setOnStart(
update):void
Attach or replace the start hook after construction. The updater receives
the installed hook and returns its replacement, so callers compose instead
of clobbering a hook they didn’t know about; ignoring prev replaces it.
sandbox.setOnStart(prev => async args => { await prev?.(args); // whatever prepared the sandbox runs first await mySetup(args);});Errors stay FATAL, so a throw stops the hooks after it. Each call wraps the current hook, so attach once per sandbox or the work stacks.
Parameters
Section titled “Parameters”update
Section titled “update”(previous) => SandboxStartHook
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”MastraSandbox.setOnStart
setWorkingDirectory()
Section titled “setWorkingDirectory()”
protectedsetWorkingDirectory(dir):void
Set the effective working directory after construction. For providers that resolve the value themselves — a computed default, or a runtime probe that needs a running VM — so the workingDirectory getter stays truthful.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”MastraSandbox.setWorkingDirectory
snapshot()
Section titled “snapshot()”snapshot():
Promise<void>
Persist the sandbox’s current state when supported.
The default implementation is a no-op for providers without snapshot support.
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”MastraSandbox.snapshot
start()
Section titled “start()”start():
Promise<void>
Warm the shared crash-isolated worker pool.
Returns
Section titled “Returns”Promise<void>
Overrides
Section titled “Overrides”MastraSandbox.start
stop()
Section titled “stop()”stop():
Promise<void>
The process-wide pool stays warm; this instance carries no open session.
Returns
Section titled “Returns”Promise<void>
Overrides
Section titled “Overrides”MastraSandbox.stop
toRawConfig()
Section titled “toRawConfig()”toRawConfig():
Record<string,unknown> |undefined
Returns the raw storage configuration this primitive was created from, or undefined if it was created from code.
Returns
Section titled “Returns”Record<string, unknown> | undefined
Inherited from
Section titled “Inherited from”MastraSandbox.toRawConfig
unmount()?
Section titled “unmount()?”
optionalunmount(mountPath):Promise<void>
Optional unmount method
Parameters
Section titled “Parameters”mountPath
Section titled “mountPath”string
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”MastraSandbox.unmount
writeFiles()?
Section titled “writeFiles()?”
optionalwriteFiles(files,options?):Promise<void>
Optional bulk file upload into the sandbox’s own filesystem.
Method syntax (not property syntax) is intentional — it prevents
useDefineForClassFields from emitting this.writeFiles = undefined
which would shadow prototype methods defined by subclasses.
Parameters
Section titled “Parameters”SandboxFileInput[]
options?
Section titled “options?”WriteFilesOptions
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”MastraSandbox.writeFiles