Interface: ICodeSandbox
Defined in: packages/agentos/src/core/sandbox/ICodeSandbox.ts:196
Interface for the Code Execution Sandbox.
Example
const sandbox = new CodeSandbox();
const result = await sandbox.execute({
language: 'python',
code: `
import json
data = {"result": 42}
print(json.dumps(data))
`,
});
console.log(result.output?.stdout); // '{"result": 42}'
Methods
dispose()
dispose():
Promise<void>
Defined in: packages/agentos/src/core/sandbox/ICodeSandbox.ts:267
Disposes of the sandbox and cleans up resources.
Returns
Promise<void>
execute()
execute(
request):Promise<ExecutionResult>
Defined in: packages/agentos/src/core/sandbox/ICodeSandbox.ts:209
Executes code in the sandbox.
Parameters
request
Execution request
Returns
Promise<ExecutionResult>
Execution result
getExecution()
getExecution(
executionId):Promise<ExecutionResult|undefined>
Defined in: packages/agentos/src/core/sandbox/ICodeSandbox.ts:223
Gets the status of an execution.
Parameters
executionId
string
ID of the execution
Returns
Promise<ExecutionResult | undefined>
Current execution result or undefined
getStats()
getStats():
SandboxStats
Defined in: packages/agentos/src/core/sandbox/ICodeSandbox.ts:249
Gets sandbox statistics.
Returns
Current statistics
getSupportedLanguages()
getSupportedLanguages():
SandboxLanguage[]
Defined in: packages/agentos/src/core/sandbox/ICodeSandbox.ts:243
Gets supported languages.
Returns
Array of supported languages
initialize()
initialize(
logger?,defaultConfig?):Promise<void>
Defined in: packages/agentos/src/core/sandbox/ICodeSandbox.ts:202
Initializes the sandbox.
Parameters
logger?
Logger instance
defaultConfig?
Default configuration
Returns
Promise<void>
isLanguageSupported()
isLanguageSupported(
language):boolean
Defined in: packages/agentos/src/core/sandbox/ICodeSandbox.ts:237
Checks if a language is supported.
Parameters
language
string
Language to check
Returns
boolean
Whether the language is supported
kill()
kill(
executionId):Promise<boolean>
Defined in: packages/agentos/src/core/sandbox/ICodeSandbox.ts:216
Kills a running execution.
Parameters
executionId
string
ID of the execution to kill
Returns
Promise<boolean>
Whether the kill was successful
listExecutions()
listExecutions(
limit?):Promise<ExecutionResult[]>
Defined in: packages/agentos/src/core/sandbox/ICodeSandbox.ts:230
Lists recent executions.
Parameters
limit?
number
Maximum number to return
Returns
Promise<ExecutionResult[]>
Array of execution results
resetStats()
resetStats():
void
Defined in: packages/agentos/src/core/sandbox/ICodeSandbox.ts:254
Resets statistics.
Returns
void
validateCode()
validateCode(
language,code):SecurityEvent[]
Defined in: packages/agentos/src/core/sandbox/ICodeSandbox.ts:262
Validates code for obvious security issues.
Parameters
language
Programming language
code
string
Code to validate
Returns
Array of security concerns