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

# Sandboxes

> Reconstructing your Python environment before compiling.

Muna supports defining custom sandboxes that can be used to reconstruct your Python environment before compiling your function.

<Warning>
  Sandboxes are very much experimental, and will likely see major changes, additions, and revisions in the near future.
</Warning>

<AccordionGroup>
  <Accordion title="Installing Python Packages">
    Use the `Sandbox.pip_install` method to install Python packages from the PyPi registry:

    ```py model.py icon="python" theme={null}
    from muna import compile, Sandbox

    # Install numpy and sklearn
    sandbox = (Sandbox()
      .pip_install("numpy", "scikit-learn")
    )

    # Compile your function with the sandbox
    @compile(..., sandbox=sandbox)
    def predict() -> np.ndarray:
        ...
    ```

    <Warning>
      We highly recommend pinning the specific versions of Python packages in use, so as to
      prevent incompatibilities when creating the sandbox.
    </Warning>
  </Accordion>

  <Accordion title="Installing Debian Packages">
    Use the `Sandbox.apt_install` method to install Debian system packages:

    ```py model.py icon="python" theme={null}
    from muna import compile, Sandbox

    # Install git and wget
    sandbox = (Sandbox()
      .apt_install("git", "wget")
    )

    # Compile your function with the sandbox
    @compile(..., sandbox=sandbox)
    def predict() -> BytesIO:
        ...
    ```
  </Accordion>

  <Accordion title="Defining Environment Variables">
    Use the `Sandbox.env` method to define plaintext environment variables:

    ```py model.py icon="python" theme={null}
    from muna import compile, Sandbox

    # Define an environment variable
    sandbox = (Sandbox()
      .env({ "MUNA_WEBSITE": "https://muna.ai" })
    )

    # Compile your function with the sandbox
    @compile(..., sandbox=sandbox)
    def predict(prompt: str) -> str:
        ...
    ```

    <Warning>
      Muna does not yet support defining secrets. **Do not** provide secrets
      using sandbox environment variables as they are not designed for storing secrets.
    </Warning>
  </Accordion>

  <Accordion title="Uploading Files">
    Use the `Sandbox.upload_file` method to upload a file to a path in the sandbox:

    ```py model.py icon="python" theme={null}
    from muna import compile, Sandbox

    # Upload a model weight to the sandbox
    sandbox = (Sandbox()
      .upload_file("DeepSeek-R1.gguf", "/Deepseek-R1.gguf")
    )

    # Compile your function with the sandbox
    @compile(..., sandbox=sandbox)
    def predict(prompt: str) -> str:
        ...
    ```
  </Accordion>

  <Accordion title="Uploading Directories">
    Use the `Sandbox.upload_directory` method to upload a directory and all its contents to a path in the sandbox:

    ```py model.py icon="python" theme={null}
    from muna import compile, Sandbox

    # Upload a directory to the sandbox
    sandbox = (Sandbox()
      .upload_file("resources/", "/resources")
    )

    # Compile your function with the sandbox
    @compile(..., sandbox=sandbox)
    def predict(prompt: str) -> str:
        ...
    ```
  </Accordion>
</AccordionGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.