code_executor
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| RemoteCodeExecutor llmling_agent.resource_providers.codemode.code_executor Provides secure code execution with tool access via FastAPI server. |
||
| ToolServerLifecycleHandler llmling_agent.resource_providers.codemode.code_executor Manages FastAPI server lifecycle for tool access. |
🛈 DocStrings¶
Code execution provider with secure tool isolation via FastAPI server.
RemoteCodeExecutor
dataclass
¶
Provides secure code execution with tool access via FastAPI server.
Architecture: - FastAPI server runs in HOST environment with tool routes - User code runs in SANDBOX environment (Docker, E2B, etc.) - Sandbox makes HTTP calls to server for tool execution
Source code in src/llmling_agent/resource_providers/codemode/code_executor.py
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 | |
execution_env
instance-attribute
¶
execution_env: ExecutionEnvironment
Execution environment for running code.
toolset_generator
instance-attribute
¶
toolset_generator: ToolsetCodeGenerator
Code generator for tools.
__aenter__
async
¶
__aenter__() -> Self
Async context manager entry.
Source code in src/llmling_agent/resource_providers/codemode/code_executor.py
90 91 92 93 | |
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Async context manager exit.
Source code in src/llmling_agent/resource_providers/codemode/code_executor.py
95 96 97 98 99 100 101 102 | |
execute_code
async
¶
execute_code(code: str) -> Any
Execute code with tools available via HTTP API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Python code to execute |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Execution result from the environment |
Source code in src/llmling_agent/resource_providers/codemode/code_executor.py
79 80 81 82 83 84 85 86 87 88 | |
from_tools
classmethod
¶
from_tools(
tools: Sequence[Tool],
env_config: ExecutionEnvironmentConfig,
server_host: str = "localhost",
server_port: int = 8000,
include_docstrings: bool = True,
) -> RemoteCodeExecutor
Create provider from tools and environment configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools
|
Sequence[Tool]
|
Tools to make available for code execution |
required |
env_config
|
ExecutionEnvironmentConfig
|
Execution environment configuration |
required |
server_host
|
str
|
Host for FastAPI server |
'localhost'
|
server_port
|
int
|
Port for FastAPI server |
8000
|
include_docstrings
|
bool
|
Include function docstrings in documentation |
True
|
Returns:
| Type | Description |
|---|---|
RemoteCodeExecutor
|
RemoteCodeExecutor instance |
Source code in src/llmling_agent/resource_providers/codemode/code_executor.py
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 | |
get_tool_description
¶
get_tool_description() -> str
Get comprehensive description of available tools.
Source code in src/llmling_agent/resource_providers/codemode/code_executor.py
75 76 77 | |
ToolServerLifecycleHandler
¶
Manages FastAPI server lifecycle for tool access.
Source code in src/llmling_agent/resource_providers/codemode/code_executor.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
__aenter__
async
¶
__aenter__() -> ServerInfo
Start FastAPI server with tool routes.
Source code in src/llmling_agent/resource_providers/codemode/code_executor.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Stop FastAPI server.
Source code in src/llmling_agent/resource_providers/codemode/code_executor.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
add_numbers
¶
add_numbers(x: int, y: int) -> int
Add two numbers.
Source code in src/llmling_agent/resource_providers/codemode/code_executor.py
201 202 203 | |