Skip to content

PosixShellSandbox

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

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).

new PosixShellSandbox(): PosixShellSandbox;

PosixShellSandbox

Sandbox.constructor

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.

| Parameter | Type | Description | | ---------- | -------------------------------------- | --------------------------------- | | command | string | The shell command to execute. | | options? | ExecuteOptions | Execution options (timeout, cwd). |

AsyncIterable< | StreamChunk | ExecutionResult>

Async iterable yielding StreamChunks followed by a final ExecutionResult.

Sandbox.executeStreaming


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.

| Parameter | Type | Description | | ---------- | -------------------------------------- | --------------------------------- | | command | string | The shell command to execute. | | options? | ExecuteOptions | Execution options (timeout, cwd). |

Promise<ExecutionResult>

The execution result with exit code and output.

Sandbox.execute


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.

| Parameter | Type | Description | | ---------- | -------------------------------------- | --------------------------------- | | code | string | The source code to execute. | | language | string | The interpreter to use. | | options? | ExecuteOptions | Execution options (timeout, cwd). |

Promise<ExecutionResult>

The execution result with exit code and output.

Sandbox.executeCode


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.

| Parameter | Type | Description | | --------- | -------- | ------------------------- | | path | string | Path 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: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.

| Parameter | Type | Description | | --------- | -------- | -------------------------- | | path | string | Path to the file to write. | | content | string | The text content to write. |

Promise<void>

Sandbox.writeText


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

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

Execute source code via a language interpreter, streaming output.

| Parameter | Type | Description | | ---------- | -------------------------------------- | ----------------------------------------------------- | | code | string | The source code to execute. | | language | string | The interpreter to use (e.g., "python3", "node"). | | options? | ExecuteOptions | Execution options (timeout, cwd). |

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:56

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.

| Parameter | Type | Description | | --------- | -------- | ------------------------- | | path | string | Path 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:64

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.

| Parameter | Type | Description | | --------- | ------------ | -------------------------- | | path | string | Path to the file to write. | | content | Uint8Array | The content to write. |

Promise<void>

Sandbox.writeFile


removeFile(path): Promise<void>;

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

Remove a file from the sandbox filesystem.

| Parameter | Type | Description | | --------- | -------- | --------------------------- | | path | string | Path 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:82

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.

| Parameter | Type | Description | | --------- | -------- | ------------------------------ | | path | string | Path to the directory to list. |

Promise<FileInfo[]>

Array of FileInfo entries for the directory contents.

Error if the directory does not exist.

Sandbox.listFiles