Skip to content

PosixShellSandbox

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

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.

ParameterTypeDescription
commandstringThe shell command to execute.
options?ExecuteOptionsExecution 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.

ParameterTypeDescription
commandstringThe shell command to execute.
options?ExecuteOptionsExecution 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.

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.

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.

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

Sandbox.writeText


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

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

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

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

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

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

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

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