Appearance
Class: Code
📖 Related Tutorial
- Code Execution Guide - Execute code in isolated environments
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-1image 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<EnhancedCodeExecutionResult>
Parameters
| Name | Type | Default value |
|---|---|---|
code | string | undefined |
language | string | undefined |
timeoutS | number | 60 |
Returns
Promise<EnhancedCodeExecutionResult>
session
• Protected session: SessionLike
Inherited from
BaseService.session
Methods
callMcpTool
▸ callMcpTool(name, args, readTimeout?, connectTimeout?): Promise<OperationResult>
Parameters
| Name | Type |
|---|---|
name | string |
args | Record<string, unknown> |
readTimeout? | number |
connectTimeout? | number |
Returns
Promise<OperationResult>
Inherited from
BaseService.callMcpTool
handleError
▸ handleError(e): unknown
Parameters
| Name | Type |
|---|---|
e | unknown |
Returns
unknown
Inherited from
BaseService.handleError
run
▸ run(code, language, timeoutS?): Promise<EnhancedCodeExecutionResult>
Run code in the session.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
code | string | undefined | Source code to execute |
language | string | undefined | Language identifier (e.g. "python", "javascript", "java", "r") |
timeoutS | number | 60 | Timeout in seconds (default 60) |
Returns
Promise<EnhancedCodeExecutionResult>
Promise resolving to EnhancedCodeExecutionResult with results and logs
toJSON
▸ toJSON(): Record<string, unknown>
Returns
Record<string, unknown>
Inherited from
BaseService.toJSON
Best Practices
- Validate code syntax before execution
- Set appropriate execution timeouts
- Handle execution errors and exceptions
- Use proper resource limits to prevent resource exhaustion
- Clean up temporary files after code execution