Skip to content

Tool API

Tool

Tool(*, name: Optional[str] = None, description: Optional[str] = None, parameters: Optional[ToolParams] = None, enabled: bool = True, timeout: Optional[int] = None, **kwargs)

              flowchart TD
              ms_enclave.sandbox.tools.base.Tool[Tool]

              

              click ms_enclave.sandbox.tools.base.Tool href "" "ms_enclave.sandbox.tools.base.Tool"
            

Base class for all tools.

Methods:

  • execute

    Execute the tool with given sandbox context and parameters.

  • is_compatible_with_sandbox

    Check if this tool is compatible with the given sandbox type.

Attributes:

Source code in ms_enclave/sandbox/tools/base.py
def __init__(
    self,
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    parameters: Optional[ToolParams] = None,
    enabled: bool = True,
    timeout: Optional[int] = None,
    **kwargs,
):
    self._name = name or self.__class__.__name__
    self._description = description
    self._parameters = parameters
    self.enabled = enabled
    self.timeout = timeout

required_sandbox_types abstractmethod property

required_sandbox_types: Optional[List[SandboxType]]

Return the list of sandbox types this tool can run in.

If a tool specifies required_sandbox_types, it can be used in: 1. Sandboxes whose type is in that list 2. Sandboxes that "inherit" from any of those types (e.g., DOCKER_NOTEBOOK inherits from DOCKER and can therefore use tools requiring DOCKER)

Returns:

  • Optional[List[SandboxType]]

    List of accepted sandbox types, or None/empty list to accept any

  • Optional[List[SandboxType]]

    sandbox type.

execute abstractmethod async

execute(sandbox_context: Sandbox, **kwargs) -> ToolResult

Execute the tool with given sandbox context and parameters.

Source code in ms_enclave/sandbox/tools/base.py
@abstractmethod
async def execute(self, sandbox_context: 'Sandbox', **kwargs) -> ToolResult:
    """Execute the tool with given sandbox context and parameters."""
    pass

is_compatible_with_sandbox

is_compatible_with_sandbox(sandbox_type: SandboxType) -> bool

Check if this tool is compatible with the given sandbox type.

Parameters:

  • sandbox_type

    (SandboxType) –

    The sandbox type to check compatibility with

Returns:

  • bool

    True if the tool can be used in the given sandbox type

Source code in ms_enclave/sandbox/tools/base.py
def is_compatible_with_sandbox(self, sandbox_type: SandboxType) -> bool:
    """
    Check if this tool is compatible with the given sandbox type.

    Args:
        sandbox_type: The sandbox type to check compatibility with

    Returns:
        True if the tool can be used in the given sandbox type
    """
    required = self.required_sandbox_types
    if not required:
        return True

    return any(SandboxType.is_compatible(sandbox_type, rt) for rt in required)

ToolFactory

Factory for creating tool instances.

register_tool

register_tool(tool_name: str)
Source code in ms_enclave/sandbox/tools/base.py
def register_tool(tool_name: str):

    def decorator(tool_class: Type[Tool]):
        ToolFactory.register_tool(tool_name, tool_class)
        return tool_class

    return decorator