CodeInterpreterClient
Source: leap0/_sync/code_interpreter.py
Signature
Section titled “Signature”CodeInterpreterClient(transport: Transport, *, sandbox_domain: str | None = None)Overview
Section titled “Overview”Execute code inside a sandbox using a managed interpreter runtime.
Supports Python and TypeScript/JavaScript. Each execution can be linked to a persistent context to share state across multiple calls.
Example:
result = sandbox.code_interpreter.execute( code="sum([1, 2, 3])", language="python",)print(result.main_text)Attributes: None.
Methods
Section titled “Methods”health
Section titled “health”health(sandbox: SandboxRef, http_timeout: float | None = None) -> boolCheck whether the code interpreter is healthy.
Args: sandbox: Sandbox ID or object. http_timeout: Optional HTTP request timeout in seconds for this SDK call.
Returns:
bool: True when the service reports "ok".
create_context
Section titled “create_context”create_context(sandbox: SandboxRef, *, language: str = 'python', cwd: str | None = None, http_timeout: float | None = None) -> CodeContextCreate a new execution context.
Args:
sandbox: Sandbox ID or object.
language: Language runtime (default "python").
cwd: Working directory for the new context.
http_timeout: Optional HTTP request timeout in seconds for this SDK call.
Returns: CodeContext: Newly created persistent execution context.
list_contexts
Section titled “list_contexts”list_contexts(sandbox: SandboxRef, http_timeout: float | None = None) -> list[CodeContext]List all execution contexts in the sandbox.
Args: sandbox: Sandbox ID or object. http_timeout: Optional HTTP request timeout in seconds for this SDK call.
Returns: list[CodeContext]: Active execution contexts.
get_context
Section titled “get_context”get_context(sandbox: SandboxRef, context_id: str, http_timeout: float | None = None) -> CodeContextGet a single execution context by ID.
Args: sandbox: Sandbox ID or object. context_id: Execution context identifier. http_timeout: Optional HTTP request timeout in seconds for this SDK call.
Returns: CodeContext: Matching execution context.
delete_context
Section titled “delete_context”delete_context(sandbox: SandboxRef, context_id: str, http_timeout: float | None = None) -> NoneDelete an execution context.
Args: sandbox: Sandbox ID or object. context_id: Execution context identifier. http_timeout: Optional HTTP request timeout in seconds for this SDK call.
execute
Section titled “execute”execute(sandbox: SandboxRef, *, code: str, language: str = 'python', context_id: str | None = None, env_vars: dict[str, str] | None = None, timeout_ms: int | None = None, http_timeout: float | None = None) -> CodeExecutionResultExecute code and wait for the full result.
Args:
sandbox: Sandbox ID or object.
code: Source code to execute.
language: Language runtime (default "python").
context_id: Link to an existing context to share state.
Auto-generated if omitted.
env_vars: Environment variables for the execution.
timeout_ms: Execution timeout in milliseconds (default 30000).
http_timeout: Optional HTTP request timeout in seconds for this SDK call.
Returns: CodeExecutionResult: Structured execution output, errors, and logs.
execute_stream
Section titled “execute_stream”execute_stream(sandbox: SandboxRef, *, code: str, language: str = 'python', context_id: str | None = None, timeout_ms: int | None = None, http_timeout: float | None = None) -> Iterator[StreamEvent]Execute code and stream output events via SSE.
Yields :class:StreamEvent objects with type "stdout",
"stderr", "exit", or "error".
Args: sandbox: Sandbox ID or object. code: Source code to execute. language: Language runtime for the operation. context_id: Parameter for this operation. timeout_ms: Execution timeout in milliseconds. http_timeout: Optional HTTP request timeout in seconds for this SDK call.
Yields: object: Items yielded by this operation.