Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/content/docs/sandbox/api/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const result = await sandbox.exec(command: string, options?: ExecOptions): Promi
- `stream` - Enable streaming callbacks (default: `false`)
- `onOutput` - Callback for real-time output: `(stream: 'stdout' | 'stderr', data: string) => void`
- `timeout` - Maximum execution time in milliseconds
- `env` - Environment variables for this command (temporarily override session/sandbox-level variables)
- `cwd` - Working directory for this command execution

**Returns**: `Promise<ExecuteResponse>` with `success`, `stdout`, `stderr`, `exitCode`

Expand All @@ -38,6 +40,12 @@ if (result.success) {
console.error('Build failed:', result.stderr);
}

// With custom environment and working directory
await sandbox.exec('node app.js', {
env: { NODE_ENV: 'production', PORT: '3000' },
cwd: '/workspace/my-app'
});

// With streaming
await sandbox.exec('npm install', {
stream: true,
Expand All @@ -56,7 +64,9 @@ const stream = await sandbox.execStream(command: string, options?: ExecOptions):

**Parameters**:
- `command` - The command to execute
- `options` - Same as `exec()`
- `options` (optional):
- `env` - Environment variables for this command (temporarily override session/sandbox-level variables)
- `cwd` - Working directory for this command execution

**Returns**: `Promise<ReadableStream>` emitting `ExecEvent` objects (`start`, `stdout`, `stderr`, `complete`, `error`)

Expand Down Expand Up @@ -93,8 +103,9 @@ const process = await sandbox.startProcess(command: string, options?: ProcessOpt
**Parameters**:
- `command` - The command to start as a background process
- `options` (optional):
- `cwd` - Working directory
- `env` - Environment variables
- `env` - Environment variables for this process (temporarily override session/sandbox-level variables)
- `cwd` - Working directory for this process
- `processId` - Custom process ID (auto-generated if not provided)

**Returns**: `Promise<ProcessInfo>` with `id`, `pid`, `command`, `status`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ await sandbox.exec("node app.js", {
},
});

// Also works with execStream()
await sandbox.execStream("python analyze.py", {
env: {
OPENAI_API_KEY: env.OPENAI_API_KEY,
},
});

// Also works with startProcess()
await sandbox.startProcess("python server.py", {
env: {
Expand Down
Loading