Execute a command in the sandbox.
When wait is true (default) and no streaming callbacks are provided,
tries WebSocket first and falls back to HTTP POST.
When wait is false or streaming callbacks are provided, uses WebSocket
(required). Returns a CommandHandle for streaming output.
run(command: string, options: RunOptions __type): Promise<CommandHandle>| Name | Type | Description |
|---|---|---|
command* | string | Shell command to execute. |
options* | RunOptions & __type | Execution options. |
// Blocking (default)
const result = await sandbox.run("echo hello");
console.log(result.stdout);
// Streaming with callbacks
const result = await sandbox.run("make build", {
onStdout: (data) => process.stdout.write(data),
});
// Non-blocking with CommandHandle
const handle = await sandbox.run("make build", { wait: false });
for await (const chunk of handle) {
process.stdout.write(chunk.data);
}
const result = await handle.result;