Skip to content

Sandbox

Defined in: src/sandbox/base.ts:35

Abstract execution environment.

A Sandbox provides the runtime context where tools execute code, run commands, and interact with a filesystem. Multiple tools share the same Sandbox instance, giving them a common working directory and filesystem.

Streaming methods (executeStreaming, executeCodeStreaming) are the abstract primitives. Non-streaming convenience methods (execute, executeCode) consume the stream and return the final result.

new Sandbox(): Sandbox;

Sandbox

abstract executeStreaming(command, options?): AsyncIterable<
| StreamChunk
| ExecutionResult>;

Defined in: src/sandbox/base.ts:47

Execute a shell command, streaming output.

Yields StreamChunk objects for stdout and stderr as output arrives. The final yield is an ExecutionResult with the exit code and complete output.

ParameterTypeDescription
commandstringThe shell command to execute.
options?ExecuteOptionsExecution options (timeout, cwd).

AsyncIterable< | StreamChunk | ExecutionResult>

Async iterable yielding StreamChunks followed by a final ExecutionResult.


abstract executeCodeStreaming(
code,
language,
options?): AsyncIterable<
| StreamChunk
| ExecutionResult>;

Defined in: src/sandbox/base.ts:57

Execute source code via a language interpreter, streaming output.

ParameterTypeDescription
codestringThe source code to execute.
languagestringThe interpreter to use (e.g., "python3", "node").
options?ExecuteOptionsExecution options (timeout, cwd).

AsyncIterable< | StreamChunk | ExecutionResult>

Async iterable yielding StreamChunks followed by a final ExecutionResult.


abstract readFile(path): Promise<Uint8Array<ArrayBufferLike>>;

Defined in: src/sandbox/base.ts:73

Read a file from the sandbox filesystem as raw bytes.

Returns Uint8Array to support both text and binary files. Use readText for a convenience wrapper that decodes to a string.

ParameterTypeDescription
pathstringPath to the file to read.

Promise<Uint8Array<ArrayBufferLike>>

The file contents as raw bytes.

Error if the file does not exist.


abstract writeFile(path, content): Promise<void>;

Defined in: src/sandbox/base.ts:84

Write raw bytes to a file in the sandbox filesystem.

Implementations should create parent directories if they do not exist. Use writeText for a convenience wrapper that encodes a string.

ParameterTypeDescription
pathstringPath to the file to write.
contentUint8ArrayThe content to write.

Promise<void>


abstract removeFile(path): Promise<void>;

Defined in: src/sandbox/base.ts:92

Remove a file from the sandbox filesystem.

ParameterTypeDescription
pathstringPath to the file to remove.

Promise<void>

Error if the file does not exist.


abstract listFiles(path): Promise<FileInfo[]>;

Defined in: src/sandbox/base.ts:105

List files in a sandbox directory.

Returns FileInfo entries with name, isDir, and size metadata. Fields isDir and size may be undefined if the backend cannot determine them.

ParameterTypeDescription
pathstringPath to the directory to list.

Promise<FileInfo[]>

Array of FileInfo entries for the directory contents.

Error if the directory does not exist.


execute(command, options?): Promise<ExecutionResult>;

Defined in: src/sandbox/base.ts:119

Execute a shell command and return the result.

Consumes executeStreaming and returns the final ExecutionResult. Use executeStreaming when you need to process output as it arrives.

ParameterTypeDescription
commandstringThe shell command to execute.
options?ExecuteOptionsExecution options (timeout, cwd).

Promise<ExecutionResult>

The execution result with exit code and output.


executeCode(
code,
language,
options?): Promise<ExecutionResult>;

Defined in: src/sandbox/base.ts:139

Execute source code and return the result.

Consumes executeCodeStreaming and returns the final ExecutionResult. Use executeCodeStreaming when you need to process output as it arrives.

ParameterTypeDescription
codestringThe source code to execute.
languagestringThe interpreter to use.
options?ExecuteOptionsExecution options (timeout, cwd).

Promise<ExecutionResult>

The execution result with exit code and output.


readText(path): Promise<string>;

Defined in: src/sandbox/base.ts:157

Read a text file from the sandbox filesystem.

Convenience wrapper over readFile that decodes bytes as UTF-8. For other encodings, call readFile and decode manually.

ParameterTypeDescription
pathstringPath to the file to read.

Promise<string>

The file contents decoded as a UTF-8 string.


writeText(path, content): Promise<void>;

Defined in: src/sandbox/base.ts:170

Write a text file to the sandbox filesystem.

Convenience wrapper over writeFile that encodes a string as UTF-8. For other encodings, encode manually and call writeFile.

ParameterTypeDescription
pathstringPath to the file to write.
contentstringThe text content to write.

Promise<void>