Code Tools
rllm.tools.code_tools
E2BPythonInterpreter
Bases: CodeTool
A tool for executing Python code in a sandboxed environment.
Source code in rllm/tools/code_tools/e2b_tool.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
forward
Execute Python code in one of the sandboxes using round-robin distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Python code to execute |
required |
timeout
|
int
|
Maximum execution time in seconds |
20
|
**kwargs
|
Additional parameters including id, max_retries |
{}
|
Returns:
| Type | Description |
|---|---|
CodeToolOutput
|
CodeToolOutput containing execution results, stdout, and stderr |
Source code in rllm/tools/code_tools/e2b_tool.py
LCBPythonInterpreter
Bases: CodeTool
A tool for executing Python code in a sandboxed environment.
This tool provides a safe way to execute Python code with timeout protection and isolation from the main process, using the LiveCodeBench execution environment.
Source code in rllm/tools/code_tools/lcb_tool.py
__init__
Initialize the Python interpreter tool with appropriate settings.
Source code in rllm/tools/code_tools/lcb_tool.py
forward
Execute Python code using the LiveCodeBench sandbox environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Python code to execute |
required |
timeout
|
int
|
Maximum execution time in seconds, defaults to 12 |
12
|
**kwargs
|
Additional parameters (unused but kept for compatibility) |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
CodeToolOutput |
CodeToolOutput
|
Contains execution results with stdout, stderr, and result fields |
Source code in rllm/tools/code_tools/lcb_tool.py
PythonInterpreter
Bases: CodeTool
A unified Python interpreter tool that supports multiple backends.
This class provides a common interface for executing Python code using different backend implementations, including local execution, E2B sandbox, Together API, and LiveCodeBench environment.
Source code in rllm/tools/code_tools/python_interpreter.py
__init__
__init__(backend: BackendType = 'local', n_sandboxes: int = 1, api_key: str | None = None, name: str = 'python', description: str = 'Execute Python code in a sandboxed environment. Returns results and standard output/error.')
Initialize the unified Python interpreter with the specified backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
BackendType
|
The backend to use ("local", "e2b", "together", or "lcb") |
'local'
|
n_sandboxes
|
int
|
Number of concurrent sandboxes/workers to use (for applicable backends) |
1
|
api_key
|
str | None
|
API key for cloud-based backends (e2b, together) |
None
|
name
|
str
|
The name of the tool |
'python'
|
description
|
str
|
Description of what the tool does |
'Execute Python code in a sandboxed environment. Returns results and standard output/error.'
|
Source code in rllm/tools/code_tools/python_interpreter.py
forward
Execute Python code using the selected backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Python code to execute |
required |
timeout
|
int
|
Maximum execution time in seconds |
12
|
**kwargs
|
Additional parameters specific to the backend implementation |
{}
|
Returns:
| Type | Description |
|---|---|
CodeToolOutput
|
CodeToolOutput containing execution results, stdout, and stderr |
Source code in rllm/tools/code_tools/python_interpreter.py
TogetherCodeTool
Bases: CodeTool
Tool for executing Python code using Together Code Interpreter (TCI).
This tool integrates with Together's Code Interpreter API to provide a secure sandbox environment for executing Python code.
Source code in rllm/tools/code_tools/together_tool.py
__init__
Initialize the TogetherCodeTool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str | None
|
Together API key (optional, will use environment variables if not provided) |
TOGETHER_API_KEY
|
name
|
The name of the tool |
required | |
description
|
Description of what the tool does |
required |
Source code in rllm/tools/code_tools/together_tool.py
forward
Execute Python code using Together Code Interpreter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Python code to execute |
required |
timeout
|
int
|
Maximum execution time in seconds (not directly used but retained for compatibility) |
12
|
session_id
|
str | None
|
Optional session ID to maintain state between runs |
None
|
**kwargs
|
Additional parameters to pass to Together's code_interpreter.run |
{}
|
Returns:
| Type | Description |
|---|---|
CodeToolOutput
|
CodeToolOutput containing execution results, stdout, and stderr |