Sandbox API¶
Sandbox
¶
Sandbox(config: SandboxConfig, sandbox_id: Optional[str] = None)
flowchart TD
ms_enclave.sandbox.boxes.base.Sandbox[Sandbox]
click ms_enclave.sandbox.boxes.base.Sandbox href "" "ms_enclave.sandbox.boxes.base.Sandbox"
Abstract base class for all sandbox implementations.
Parameters:
-
(config¶SandboxConfig) –Sandbox configuration
-
(sandbox_id¶Optional[str], default:None) –Optional sandbox ID (will be generated if not provided)
-
API 参考
SandboxFactorycreate_sandbox
Methods:
-
__aenter__–Async context manager entry.
-
__aexit__–Async context manager exit.
-
add_tool–Add a tool to the sandbox.
-
cleanup–Clean up sandbox resources.
-
execute_command–Execute a command in the sandbox environment.
-
execute_tool–Execute a tool with given parameters.
-
get_available_tools–Get list of available tools.
-
get_execution_context–Get the execution context for tools (e.g., container, process, etc.).
-
get_info–Get sandbox information.
-
get_tool–Get tool instance by type.
-
initialize_tools–Initialize sandbox tools.
-
list_tools–List all registered tools compatible with this sandbox.
-
start–Start the sandbox environment.
-
stop–Stop the sandbox environment.
-
update_status–Update sandbox status.
Attributes:
-
sandbox_type(SandboxType) –Return the sandbox type identifier.
Source code in ms_enclave/sandbox/boxes/base.py
sandbox_type
abstractmethod
property
¶
Return the sandbox type identifier.
__aenter__
async
¶
__aexit__
async
¶
add_tool
¶
add_tool(tool: Tool) -> None
Add a tool to the sandbox.
Parameters:
-
(tool¶Tool) –Tool instance to add
Source code in ms_enclave/sandbox/boxes/base.py
cleanup
abstractmethod
async
¶
execute_command
async
¶
execute_command(command: Union[str, List[str]], timeout: Optional[int] = None, stream: bool = True) -> CommandResult
Execute a command in the sandbox environment.
Parameters:
-
(command¶Union[str, List[str]]) –Command to execute
-
(timeout¶Optional[int], default:None) –Optional execution timeout in seconds
-
(stream¶bool, default:True) –Whether to stream output (if supported)
Source code in ms_enclave/sandbox/boxes/base.py
execute_tool
async
¶
Execute a tool with given parameters.
Parameters:
Returns:
-
ToolResult–Tool execution result
Raises:
-
ValueError–If tool is not found or not enabled
-
TimeoutError–If tool execution exceeds timeout
-
Exception–For other execution errors
Source code in ms_enclave/sandbox/boxes/base.py
get_available_tools
¶
get_info
¶
Get sandbox information.
Returns:
-
SandboxInfo–Sandbox information
Source code in ms_enclave/sandbox/boxes/base.py
get_tool
¶
Get tool instance by type.
Parameters:
Returns:
-
Optional[Tool]–Tool instance or None if not available
initialize_tools
async
¶
Initialize sandbox tools.
Source code in ms_enclave/sandbox/boxes/base.py
list_tools
¶
List all registered tools compatible with this sandbox.
Returns:
start
abstractmethod
async
¶
stop
abstractmethod
async
¶
SandboxFactory
¶
Factory for creating sandbox instances.
Methods:
-
create_sandbox–Create a sandbox instance.
-
get_available_types–Get list of available sandbox types.
-
register_sandbox–Register a sandbox class.
create_sandbox
classmethod
¶
create_sandbox(sandbox_type: SandboxType, config: Optional[Union[SandboxConfig, Dict]] = None, sandbox_id: Optional[str] = None) -> Sandbox
Create a sandbox instance.
Parameters:
-
(sandbox_type¶SandboxType) –Sandbox type
-
(config¶Optional[Union[SandboxConfig, Dict]], default:None) –Sandbox configuration
-
(sandbox_id¶Optional[str], default:None) –Optional sandbox ID
Returns:
-
Sandbox–Sandbox instance
Raises:
-
ValueError–If sandbox type is not registered
Source code in ms_enclave/sandbox/boxes/base.py
get_available_types
classmethod
¶
get_available_types() -> List[SandboxType]
register_sandbox
classmethod
¶
register_sandbox(sandbox_type: SandboxType, sandbox_class: Type[Sandbox])
register_sandbox
¶
register_sandbox(sandbox_type: SandboxType)
Decorator for registering sandboxes.
Parameters:
-
(sandbox_type¶SandboxType) –Sandbox type identifier