Skip to content

PosixShellSandbox

Defined in: src/sandbox/posix-shell.ts:65

Abstract sandbox that provides shell-based defaults for file and code operations. Assumes a POSIX-compatible shell (sh/bash) on the target.

Subclasses only need to implement executeStreaming. The remaining operations — executeCodeStreaming, readFile, writeFile, removeFile, and listFiles — are implemented via shell commands piped through executeStreaming.

Subclasses may override any method with a native implementation for better performance or to handle edge cases (e.g., binary-safe file transfer via Docker stdin pipes, or native API calls for cloud backends).

Subclasses must apply options.env in executeStreaming or it has no effect: backends that build a shell-command string prepend buildShellEnvPrefix; backends that set env via process flags (e.g. Docker’s -e) call validateEnvKeys and pass the values directly.

new PosixShellSandbox(): PosixShellSandbox;

PosixShellSandbox

Sandbox.constructor

toolPrefix: string = 'sandbox';

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

Prefix applied to tool names when registered on an agent (e.g. 'sandbox' produces sandbox_bash). Set to undefined to disable prefixing. Defaults to 'sandbox'.

Sandbox.toolPrefix

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

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

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.

AsyncIterable< | StreamChunk | ExecutionResult>

Async iterable yielding StreamChunks followed by a final ExecutionResult.

Sandbox.executeStreaming


getTools(): Tool[];

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

Tools this sandbox vends to an agent, registered during Agent.initialize(). A tool is skipped if the user already registered one with the same name. Override to provide them.

Tool[]

Sandbox.getTools


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

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

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.

Promise<ExecutionResult>

The execution result with exit code and output.

Sandbox.execute


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

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

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.

Promise<ExecutionResult>

The execution result with exit code and output.

Sandbox.executeCode


readText(path): Promise<string>;

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

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.

Sandbox.readText


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

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

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>

Sandbox.writeText


executeCodeStreaming(
code,
language,
options?): AsyncGenerator<
| StreamChunk
| ExecutionResult, void, undefined>;

Defined in: src/sandbox/posix-shell.ts:66

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.

AsyncGenerator< | StreamChunk | ExecutionResult, void, undefined>

Async iterable yielding StreamChunks followed by a final ExecutionResult.

Sandbox.executeCodeStreaming


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

Defined in: src/sandbox/posix-shell.ts:79

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.

Sandbox.readFile


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

Defined in: src/sandbox/posix-shell.ts:87

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>

Sandbox.writeFile


removeFile(path): Promise<void>;

Defined in: src/sandbox/posix-shell.ts:98

Remove a file from the sandbox filesystem.

ParameterTypeDescription
pathstringPath to the file to remove.

Promise<void>

Error if the file does not exist.

Sandbox.removeFile


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

Defined in: src/sandbox/posix-shell.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.

Sandbox.listFiles