๐ป Code API Reference
March 6, 2026 ยท View on GitHub
Overview
The Code module provides secure code execution capabilities in isolated environments. It supports multiple programming languages including Python, JavaScript, and more.
๐ Tutorial
Execute code in isolated environments
๐ Requirements
- Requires
code_latestimage for code execution features
Code
Handles code execution operations in the AgentBay cloud environment.
This service provides methods to execute code in various programming languages (Python, JavaScript, R, Java) within a cloud-based code execution environment. It supports both synchronous and WebSocket-based streaming execution modes.
Constructor
public Code(Session session)
Creates a new Code service instance bound to the given session.
Parameters:
session(Session): The session to bind this code execution service to.
Methods
runCode
public EnhancedCodeExecutionResult runCode(String code, String language, int timeoutS)
public EnhancedCodeExecutionResult runCode(String code, String language, int timeoutS, boolean streamBeta, Consumer<String> onStdout, Consumer<String> onStderr, Consumer<Object> onError)
public EnhancedCodeExecutionResult runCode(String code, String language)
Execute code with optional WebSocket streaming for real-time stdout/stderr output.
Parameters:
code(String): The code to execute.language(String): The programming language of the code. Case-insensitive.timeoutS(int): The timeout for the code execution in seconds.streamBeta(boolean): If true, use WebSocket streaming for real-time output.onStdout(Consumer): Callback invoked for each stdout chunk. May be null. onStderr(Consumer): Callback invoked for each stderr chunk. May be null. onError(Consumer