Interface ICodeSandbox

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}'
interface ICodeSandbox {
    initialize(logger?, defaultConfig?): Promise<void>;
    execute(request): Promise<ExecutionResult>;
    kill(executionId): Promise<boolean>;
    getExecution(executionId): Promise<undefined | ExecutionResult>;
    listExecutions(limit?): Promise<ExecutionResult[]>;
    isLanguageSupported(language): boolean;
    getSupportedLanguages(): SandboxLanguage[];
    getStats(): SandboxStats;
    resetStats(): void;
    validateCode(language, code): SecurityEvent[];
    dispose(): Promise<void>;
}

Implemented by

Methods

  • Kills a running execution.

    Parameters

    • executionId: string

      ID of the execution to kill

    Returns Promise<boolean>

    Whether the kill was successful

  • Checks if a language is supported.

    Parameters

    • language: string

      Language to check

    Returns boolean

    Whether the language is supported