Microsandbox Code Interpreter implementation.This interpreter provides secure code execution using microsandbox,
a self-hosted platform for secure execution of untrusted user/AI code.
It supports Python code execution via PythonSandbox, JavaScript/Node.js
code execution via NodeSandbox, and shell commands via the command
interface.Parameters:
require_confirm (bool, optional): If True, prompt user before running code strings for security. (default: :obj:True)
server_url (str, optional): URL of the microsandbox server. If not provided, will use MSB_SERVER_URL environment variable, then fall back to http://127.0.0.1:5555. (default: :obj:None)
api_key (str, optional): API key for microsandbox authentication. If not provided, will use MSB_API_KEY environment variable. (default: :obj:None)
namespace (str, optional): Namespace for the sandbox. (default: :obj:"default")
sandbox_name (str, optional): Name of the sandbox instance. If not provided, a random name will be generated by the SDK. (default: :obj:None)
timeout (int, optional): Default timeout for code execution in seconds. (default: :obj:30) Environment Variables:
MSB_SERVER_URL: URL of the microsandbox server.
MSB_API_KEY: API key for microsandbox authentication.
Execute a shell command in the microsandbox.This method is designed for package management and system
administration tasks. It executes shell commands directly
using the microsandbox command interface.Parameters:
command (str): The shell command to execute (e.g., “pip install numpy”, “ls -la”, “apt-get update”).
Returns:Union[str, Tuple[str, str]]: The output of the command.