Skip to content

Class: Code

Overview

The Code module provides secure code execution capabilities in isolated environments. It supports multiple programming languages including Python, JavaScript, and more.

Requirements

  • Requires agb-code-space-1 image for code execution features

Code execution module for running code in the session (Python, JavaScript, Java, R).

Hierarchy

  • BaseService

    Code

Table of contents

Properties

Methods

Properties

typescript
execute: (`code`: `string`, `language`: `string`, `timeoutS`: `number`) => `Promise`<``EnhancedCodeExecutionResult``>

Type declaration

▸ (code, language, timeoutS?): Promise&lt;EnhancedCodeExecutionResult&gt;

Parameters
NameTypeDefault value
codestringundefined
languagestringundefined
timeoutSnumber60
Returns

Promise&lt;EnhancedCodeExecutionResult&gt;


session

Protected session: SessionLike

Inherited from

BaseService.session

Methods

callMcpTool

callMcpTool(name, args, readTimeout?, connectTimeout?): Promise&lt;OperationResult&gt;

Parameters

NameType
namestring
argsRecord&lt;string, unknown&gt;
readTimeout?number
connectTimeout?number

Returns

Promise&lt;OperationResult&gt;

Inherited from

BaseService.callMcpTool


handleError

handleError(e): unknown

Parameters

NameType
eunknown

Returns

unknown

Inherited from

BaseService.handleError


run

run(code, language, timeoutS?): Promise&lt;EnhancedCodeExecutionResult&gt;

Run code in the session.

Parameters

NameTypeDefault valueDescription
codestringundefinedSource code to execute
languagestringundefinedLanguage identifier (e.g. "python", "javascript", "java", "r")
timeoutSnumber60Timeout in seconds (default 60)

Returns

Promise&lt;EnhancedCodeExecutionResult&gt;

Promise resolving to EnhancedCodeExecutionResult with results and logs


toJSON

toJSON(): Record&lt;string, unknown&gt;

Returns

Record&lt;string, unknown&gt;

Inherited from

BaseService.toJSON

Best Practices

  1. Validate code syntax before execution
  2. Set appropriate execution timeouts
  3. Handle execution errors and exceptions
  4. Use proper resource limits to prevent resource exhaustion
  5. Clean up temporary files after code execution