Skip to content

remote_mcp_execution

Class info

Classes

Name Children Inherits
RemoteMCPExecutor
llmling_agent.resource_providers.codemode.remote_mcp_execution
Provides secure code execution with tool access.

    🛈 DocStrings

    Code execution provider with secure tool isolation via FastAPI server.

    RemoteMCPExecutor dataclass

    Provides secure code execution with tool access.

    Code Generation mode (ctx-zip style): - Tool functions are generated as Python files inside sandbox - User code imports tools directly, no HTTP server needed - Better for cloud sandboxes (E2B, etc.) that can't reach localhost

    Source code in src/llmling_agent/resource_providers/codemode/remote_mcp_execution.py
     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
    @dataclass
    class RemoteMCPExecutor:
        """Provides secure code execution with tool access.
    
        Code Generation mode (ctx-zip style):
           - Tool functions are generated as Python files inside sandbox
           - User code imports tools directly, no HTTP server needed
           - Better for cloud sandboxes (E2B, etc.) that can't reach localhost
        """
    
        toolset_generator: ToolsetCodeGenerator
        """Code generator for tools."""
    
        execution_env: ExecutionEnvironment
        """Execution environment for running code."""
    
        use_code_generation: bool = False
        """If True, use code generation approach instead of HTTP server."""
    
        @classmethod
        def from_tools(
            cls,
            tools: Sequence[Tool],
            env_config: ExecutionEnvironmentConfig,
            include_docstrings: bool = True,
        ) -> RemoteMCPExecutor:
            """Create provider from tools and environment configuration.
    
            Args:
                tools: Tools to make available for code execution
                env_config: Execution environment configuration
                include_docstrings: Include function docstrings in documentation
    
            Returns:
                RemoteMCPExecutor instance
            """
            from llmling_agent.resource_providers.codemode.helpers import tools_to_codegen
    
            toolset_gen = tools_to_codegen(tools, include_docstrings)
            execution_env = env_config.get_provider()
            return cls(toolset_gen, execution_env)
    
        def get_tool_description(self) -> str:
            """Get comprehensive description of available tools."""
            # For code generation mode, provide import-based usage instructions
            tool_names = [gen.name for gen in self.toolset_generator.generators]
            desc = self.toolset_generator.generate_tool_description()
            desc += "Usage:\n"
            for name in tool_names:
                desc += f"  from tools.{name} import {name}\n"
                desc += f"  result = await {name}(...)\n"
            return desc
    
        async def execute_code(self, code: str) -> Any:
            """Execute code with tools available.
    
            Args:
                code: Python code to execute
    
            Returns:
                Execution result from the environment
            """
            return await self.execution_env.execute(code)
    
        async def __aenter__(self) -> Self:
            """Async context manager entry."""
            await self.execution_env.__aenter__()
            return self
    
        async def __aexit__(
            self,
            exc_type: type[BaseException] | None,
            exc_val: BaseException | None,
            exc_tb: TracebackType | None,
        ) -> None:
            """Async context manager exit."""
            return await self.execution_env.__aexit__(exc_type, exc_val, exc_tb)
    

    execution_env instance-attribute

    execution_env: ExecutionEnvironment
    

    Execution environment for running code.

    toolset_generator instance-attribute

    toolset_generator: ToolsetCodeGenerator
    

    Code generator for tools.

    use_code_generation class-attribute instance-attribute

    use_code_generation: bool = False
    

    If True, use code generation approach instead of HTTP server.

    __aenter__ async

    __aenter__() -> Self
    

    Async context manager entry.

    Source code in src/llmling_agent/resource_providers/codemode/remote_mcp_execution.py
    90
    91
    92
    93
    async def __aenter__(self) -> Self:
        """Async context manager entry."""
        await self.execution_env.__aenter__()
        return self
    

    __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/remote_mcp_execution.py
     95
     96
     97
     98
     99
    100
    101
    102
    async def __aexit__(
        self,
        exc_type: type[BaseException] | None,
        exc_val: BaseException | None,
        exc_tb: TracebackType | None,
    ) -> None:
        """Async context manager exit."""
        return await self.execution_env.__aexit__(exc_type, exc_val, exc_tb)
    

    execute_code async

    execute_code(code: str) -> Any
    

    Execute code with tools available.

    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/remote_mcp_execution.py
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    async def execute_code(self, code: str) -> Any:
        """Execute code with tools available.
    
        Args:
            code: Python code to execute
    
        Returns:
            Execution result from the environment
        """
        return await self.execution_env.execute(code)
    

    from_tools classmethod

    from_tools(
        tools: Sequence[Tool], env_config: ExecutionEnvironmentConfig, include_docstrings: bool = True
    ) -> RemoteMCPExecutor
    

    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
    include_docstrings bool

    Include function docstrings in documentation

    True

    Returns:

    Type Description
    RemoteMCPExecutor

    RemoteMCPExecutor instance

    Source code in src/llmling_agent/resource_providers/codemode/remote_mcp_execution.py
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    @classmethod
    def from_tools(
        cls,
        tools: Sequence[Tool],
        env_config: ExecutionEnvironmentConfig,
        include_docstrings: bool = True,
    ) -> RemoteMCPExecutor:
        """Create provider from tools and environment configuration.
    
        Args:
            tools: Tools to make available for code execution
            env_config: Execution environment configuration
            include_docstrings: Include function docstrings in documentation
    
        Returns:
            RemoteMCPExecutor instance
        """
        from llmling_agent.resource_providers.codemode.helpers import tools_to_codegen
    
        toolset_gen = tools_to_codegen(tools, include_docstrings)
        execution_env = env_config.get_provider()
        return cls(toolset_gen, execution_env)
    

    get_tool_description

    get_tool_description() -> str
    

    Get comprehensive description of available tools.

    Source code in src/llmling_agent/resource_providers/codemode/remote_mcp_execution.py
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    def get_tool_description(self) -> str:
        """Get comprehensive description of available tools."""
        # For code generation mode, provide import-based usage instructions
        tool_names = [gen.name for gen in self.toolset_generator.generators]
        desc = self.toolset_generator.generate_tool_description()
        desc += "Usage:\n"
        for name in tool_names:
            desc += f"  from tools.{name} import {name}\n"
            desc += f"  result = await {name}(...)\n"
        return desc
    

    add_numbers

    add_numbers(x: int, y: int) -> int
    

    Add two numbers.

    Source code in src/llmling_agent/resource_providers/codemode/remote_mcp_execution.py
    110
    111
    112
    def add_numbers(x: int, y: int) -> int:
        """Add two numbers."""
        return x + y
    

    multiply_numbers

    multiply_numbers(x: int, y: int) -> int
    

    Multiply two numbers.

    Source code in src/llmling_agent/resource_providers/codemode/remote_mcp_execution.py
    114
    115
    116
    def multiply_numbers(x: int, y: int) -> int:
        """Multiply two numbers."""
        return x * y