Class - Sandbox
A Sandbox is an isolated Linux MicroVM to run commands in.
Use Sandbox.create or Sandbox.get to construct.
Accessors
sandboxId
Get Signature
Unique ID of this sandbox.
Returns
string
Methods
create()
Create a new sandbox.
Parameters
Parameter | Type | Description |
---|---|---|
params? | | { source? : | { type : "git" ; url : string ; depth? : number ; revision? : string ; } | { type : "git" ; url : string ; username : string ; password : string ; depth? : number ; revision? : string ; } | { type : "tarball" ; url : string ; }; ports? : number []; timeout? : number ; resources? : { vcpus : number ; }; runtime? : "node22" | "python3.13" ; } | { source? : | { type : "git" ; url : string ; depth? : number ; revision? : string ; } | { type : "git" ; url : string ; username : string ; password : string ; depth? : number ; revision? : string ; } | { type : "tarball" ; url : string ; }; ports? : number []; timeout? : number ; resources? : { vcpus : number ; }; runtime? : "node22" | "python3.13" ; } & Credentials | Creation parameters and optional credentials. |
Returns
Promise
<Sandbox
>
A promise resolving to the created Sandbox.
get()
Retrieve an existing sandbox.
Parameters
Parameter | Type | Description |
---|---|---|
params | | { sandboxId : string ; } | { sandboxId : string ; } & Credentials | Get parameters and optional credentials. |
Returns
Promise
<Sandbox
>
A promise resolving to the Sandbox.
getCommand()
Get a previously run command by its ID.
Parameters
Parameter | Type | Description |
---|---|---|
cmdId | string | ID of the command to retrieve |
Returns
Promise
<Command
>
A Command instance representing the command
runCommand()
Call Signature
Start executing a command in this sandbox.
Parameters
Parameter | Type | Description |
---|---|---|
command | string | The command to execute. |
args? | string [] | Arguments to pass to the command. |
Returns
Promise
<CommandFinished
>
A CommandFinished result once execution is done.
Call Signature
Start executing a command in detached mode.
Parameters
Parameter | Type | Description |
---|---|---|
params | { cmd : string ; args? : string []; cwd? : string ; env? : Record <string , string >; detached? : boolean ; stdout? : Writable ; stderr? : Writable ; } & { detached : true ; } | The command parameters. |
Returns
Promise
<Command
>
A Command instance for the running command.
Call Signature
Start executing a command in this sandbox.
Parameters
Parameter | Type | Description |
---|---|---|
params | { cmd : string ; args? : string []; cwd? : string ; env? : Record <string , string >; detached? : boolean ; stdout? : Writable ; stderr? : Writable ; } | The command parameters. |
params.cmd | string | The command to execute |
params.args? | string [] | Arguments to pass to the command |
params.cwd? | string | Working directory to execute the command in |
params.env? | Record <string , string > | Environment variables to set for this command |
params.detached? | boolean | If true, the command will return without waiting for exitCode |
params.stdout? | Writable | A Writable stream where stdout from the command will be piped |
params.stderr? | Writable | A Writable stream where stderr from the command will be piped |
Returns
Promise
<CommandFinished
>
A CommandFinished result once execution is done.
_runCommand()
Internal
Internal helper to start a command in the sandbox.
Parameters
Parameter | Type | Description |
---|---|---|
params | { cmd : string ; args? : string []; cwd? : string ; env? : Record <string , string >; detached? : boolean ; stdout? : Writable ; stderr? : Writable ; } | Command execution parameters. |
params.cmd | string | The command to execute |
params.args? | string [] | Arguments to pass to the command |
params.cwd? | string | Working directory to execute the command in |
params.env? | Record <string , string > | Environment variables to set for this command |
params.detached? | boolean | If true, the command will return without waiting for exitCode |
params.stdout? | Writable | A Writable stream where stdout from the command will be piped |
params.stderr? | Writable | A Writable stream where stderr from the command will be piped |
Returns
Promise
<CommandFinished
| Command
>
A Command or CommandFinished, depending on detached
.
mkDir()
Create a directory in the filesystem of this sandbox.
Parameters
Parameter | Type | Description |
---|---|---|
path | string | Path of the directory to create |
Returns
Promise
<void
>
readFile()
Read a file from the filesystem of this sandbox.
Parameters
Parameter | Type | Description |
---|---|---|
file | { path : string ; cwd? : string ; } | File to read, with path and optional cwd |
file.path | string | - |
file.cwd? | string | - |
Returns
Promise
<null
| ReadableStream
>
A promise that resolves to a ReadableStream containing the file contents
writeFiles()
Write files to the filesystem of this sandbox.
Parameters
Parameter | Type | Description |
---|---|---|
files | { path : string ; content : Buffer ; }[] | Array of files with path and stream/buffer contents |
Returns
Promise
<void
>
A promise that resolves when the files are written
domain()
Get the public domain of a port of this sandbox.
Parameters
Parameter | Type | Description |
---|---|---|
p | number | Port number to resolve |
Returns
string
A full domain (e.g. https://subdomain.vercel.run
)
Throws
If the port has no associated route
stop()
Stop the sandbox.
Returns
Promise
<void
>
A promise that resolves when the sandbox is stopped