> ## Documentation Index
> Fetch the complete documentation index at: https://docs.camel-ai.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Camel.interpreters.microsandbox interpreter

<a id="camel.interpreters.microsandbox_interpreter" />

<a id="camel.interpreters.microsandbox_interpreter.MicrosandboxInterpreter" />

## MicrosandboxInterpreter

```python theme={"system"}
class MicrosandboxInterpreter(BaseInterpreter):
```

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](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.

**Note:**

The SDK handles parameter priority as: user parameter > environment
variable > default value.

<a id="camel.interpreters.microsandbox_interpreter.MicrosandboxInterpreter.__init__" />

### **init**

```python theme={"system"}
def __init__(
    self,
    require_confirm: bool = True,
    server_url: Optional[str] = None,
    api_key: Optional[str] = None,
    namespace: str = 'default',
    sandbox_name: Optional[str] = None,
    timeout: int = 30
):
```

<a id="camel.interpreters.microsandbox_interpreter.MicrosandboxInterpreter.run" />

### run

```python theme={"system"}
def run(self, code: str, code_type: str = 'python'):
```

Executes the given code in the microsandbox.

**Parameters:**

* **code** (str): The code string to execute.
* **code\_type** (str): The type of code to execute. Supported types: 'python', 'javascript', 'bash'. (default: :obj:`python`)

**Returns:**

str: The string representation of the output of the executed code.

<a id="camel.interpreters.microsandbox_interpreter.MicrosandboxInterpreter._confirm_execution" />

### \_confirm\_execution

```python theme={"system"}
def _confirm_execution(self, execution_type: str):
```

Prompt user for confirmation before executing code or commands.

**Parameters:**

* **execution\_type** (str): Type of execution ('code' or 'command').

<a id="camel.interpreters.microsandbox_interpreter.MicrosandboxInterpreter.supported_code_types" />

### supported\_code\_types

```python theme={"system"}
def supported_code_types(self):
```

Provides supported code types by the interpreter.

<a id="camel.interpreters.microsandbox_interpreter.MicrosandboxInterpreter.update_action_space" />

### update\_action\_space

```python theme={"system"}
def update_action_space(self, action_space: Dict[str, Any]):
```

Updates action space for interpreter.

**Parameters:**

* **action\_space**: Action space dictionary (unused in microsandbox).

**Note:**

Microsandbox doesn't support action space updates as it runs
in isolated environments for each execution.

<a id="camel.interpreters.microsandbox_interpreter.MicrosandboxInterpreter.execute_command" />

### execute\_command

```python theme={"system"}
def execute_command(self, command: str):
```

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.

<a id="camel.interpreters.microsandbox_interpreter.MicrosandboxInterpreter.__del__" />

### **del**

```python theme={"system"}
def __del__(self):
```

Destructor for the MicrosandboxInterpreter class.

Microsandbox uses context managers for resource management,
so no explicit cleanup is needed.
