Skip to main content

Class: CodeSandbox

Defined in: packages/agentos/src/safety/sandbox/executor/CodeSandbox.ts:175

Code Execution Sandbox implementation.

Runs code with a time limit and a minimal set of globals: JavaScript in a node:vm context inside this process, Python in a child process. node:vm is not a security mechanism (Node's documentation).

Implements​

Constructors​

Constructor​

new CodeSandbox(defaultConfig?): CodeSandbox

Defined in: packages/agentos/src/safety/sandbox/executor/CodeSandbox.ts:182

Parameters​

defaultConfig?​

Partial<SandboxConfig>

Returns​

CodeSandbox

Methods​

dispose()​

dispose(): Promise<void>

Defined in: packages/agentos/src/safety/sandbox/executor/CodeSandbox.ts:724

Disposes of the sandbox.

Returns​

Promise<void>

Implementation of​

ICodeSandbox.dispose


execute()​

execute(request): Promise<ExecutionResult>

Defined in: packages/agentos/src/safety/sandbox/executor/CodeSandbox.ts:201

Executes code in the sandbox.

Parameters​

request​

ExecutionRequest

Returns​

Promise<ExecutionResult>

Implementation of​

ICodeSandbox.execute


getExecution()​

getExecution(executionId): Promise<ExecutionResult | undefined>

Defined in: packages/agentos/src/safety/sandbox/executor/CodeSandbox.ts:658

Gets the status of an execution.

Parameters​

executionId​

string

Returns​

Promise<ExecutionResult | undefined>

Implementation of​

ICodeSandbox.getExecution


getStats()​

getStats(): SandboxStats

Defined in: packages/agentos/src/safety/sandbox/executor/CodeSandbox.ts:688

Gets sandbox statistics.

Returns​

SandboxStats

Implementation of​

ICodeSandbox.getStats


getSupportedLanguages()​

getSupportedLanguages(): SandboxLanguage[]

Defined in: packages/agentos/src/safety/sandbox/executor/CodeSandbox.ts:681

Gets supported languages.

Returns​

SandboxLanguage[]

Implementation of​

ICodeSandbox.getSupportedLanguages


initialize()​

initialize(logger?, defaultConfig?): Promise<void>

Defined in: packages/agentos/src/safety/sandbox/executor/CodeSandbox.ts:190

Initializes the sandbox.

Parameters​

logger?​

ILogger

defaultConfig?​

SandboxConfig

Returns​

Promise<void>

Implementation of​

ICodeSandbox.initialize


isLanguageSupported()​

isLanguageSupported(language): boolean

Defined in: packages/agentos/src/safety/sandbox/executor/CodeSandbox.ts:674

Checks if a language is supported.

Parameters​

language​

string

Returns​

boolean

Implementation of​

ICodeSandbox.isLanguageSupported


kill()​

kill(executionId): Promise<boolean>

Defined in: packages/agentos/src/safety/sandbox/executor/CodeSandbox.ts:641

Kills a running execution.

Parameters​

executionId​

string

Returns​

Promise<boolean>

Implementation of​

ICodeSandbox.kill


listExecutions()​

listExecutions(limit?): Promise<ExecutionResult[]>

Defined in: packages/agentos/src/safety/sandbox/executor/CodeSandbox.ts:665

Lists recent executions.

Parameters​

limit?​

number = 50

Returns​

Promise<ExecutionResult[]>

Implementation of​

ICodeSandbox.listExecutions


resetStats()​

resetStats(): void

Defined in: packages/agentos/src/safety/sandbox/executor/CodeSandbox.ts:695

Resets statistics.

Returns​

void

Implementation of​

ICodeSandbox.resetStats


validateCode()​

validateCode(language, code): SecurityEvent[]

Defined in: packages/agentos/src/safety/sandbox/executor/CodeSandbox.ts:702

Validates code for security issues.

Parameters​

language​

SandboxLanguage

code​

string

Returns​

SecurityEvent[]

Implementation of​

ICodeSandbox.validateCode