Appearance
Code API Reference
💻 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
CodeExecutionResult
python
class CodeExecutionResult(ApiResponse)Result of code execution operations.
Code
python
class Code(BaseService)Handles code execution operations in the AGB cloud environment.
run_code
python
def run_code(code: str,
language: str,
timeout_s: int = 60) -> CodeExecutionResultExecute code in the specified language with a timeout.
Arguments:
codestr - The code to execute.languagestr - The programming language of the code. Supported languages are: 'python', 'javascript', 'java', 'r'.timeout_sint - The timeout for the code execution in seconds. Default is 60s.
Returns:
CodeExecutionResult: Result object containing success status, execution
result, and error message if any.
Raises:
CommandError: If the code execution fails or if an unsupported language is
specified.
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
Related Resources
Documentation generated automatically from source code using pydoc-markdown.