# Reach Mirli from another machine

This guide opens a Mirli server to other machines, such as a rented GPU or a
box on your LAN, with an access token so that only you can use it. It also
covers putting the server behind a reverse proxy and running it for other
people.

> [!WARNING]
> Without a token, anyone who can reach the port can generate audio, read and
> delete your library, change settings and call every MCP tool. Set a token
> before you bind any address other than loopback.

## Before you begin

- Build Mirli as described in [Run Mirli from source](https://mirli.app/docs/install/index.md), or run
  the [Docker image](https://mirli.app/docs/install-docker/index.md).
- Plan how the connection is encrypted: a reverse proxy with a certificate, a
  tunnel such as Tailscale, or a GPU host's own HTTPS proxy. Over plain
  `http://`, the token crosses the network unencrypted.

## Start the server with an access token

1. Generate a random token and put it in `MIRLI_API_TOKEN`:

   ```bash title="macOS / Linux"
   export MIRLI_API_TOKEN="$(node -p "crypto.randomBytes(32).toString('hex')")"
   ```

   ```powershell title="Windows"
   $env:MIRLI_API_TOKEN = node -p "crypto.randomBytes(32).toString('hex')"
   ```

   The token must be at least 16 characters. For Docker, pass it with
   `-e MIRLI_API_TOKEN=<TOKEN>`.

2. Start the server on every interface:

   ```bash
   soundbox --host 0.0.0.0
   ```

   The startup banner shows `Access token -> required`.

3. Open the server's address in a browser and paste the token on the sign-in
   screen. The browser stays signed in for 30 days.

4. Optional: Connect an MCP client with the token in a header. For Claude
   Code:

   ```bash
   claude mcp add --transport http soundbox https://<HOST>/mcp \
     --header "Authorization: Bearer $MIRLI_API_TOKEN"
   ```

   Replace `<HOST>` with the name or address you reach the server by. If that
   is anything other than `localhost` or `127.0.0.1`, also list it in
   `MIRLI_ALLOWED_HOSTS`, or `/mcp` answers 403.

What the token protects, and the rate limit on wrong tokens, are described in
[Access control](https://mirli.app/docs/install-access/index.md#access-token).

## Put Mirli behind a reverse proxy

1. Start the server on loopback, listing the host name the proxy forwards in
   the `Host` header:

   ```bash
   MIRLI_ALLOWED_HOSTS=mirli.lan soundbox
   ```

   To accept that name on one port only, write `mirli.lan:8443`.

2. Point Caddy or nginx at `127.0.0.1:17494`, and have it forward the
   original `Host` header.

3. If the proxy terminates HTTPS, have it send
   `X-Forwarded-Proto: https`, so the sign-in cookie is marked `Secure`.

Use an access token as well, or a proxy that authenticates (basic auth,
Authelia or Authentik).

## Open the dev servers to your network

Under `npm run dev`, the server stays on `127.0.0.1` and only Vite listens
more widely.

1. Start the dev servers with Vite listening on every interface, and list the
   name you reach it by:

   ```bash
   SOUNDBOX_DEV_HOST=0.0.0.0 SOUNDBOX_ALLOWED_HOSTS=mirli.lan npm run dev
   ```

2. Open `http://<HOST>:5174` from the other machine.

Behind a proxy on the same machine, set only `SOUNDBOX_ALLOWED_HOSTS` and
point the proxy at `127.0.0.1:5174`. For a LAN IP address, set only
`SOUNDBOX_DEV_HOST`. The dev servers have no authentication.

## Run Mirli for other people

When the people using Mirli don't own the machine it runs on, such as a shared
server or a NAS:

1. Set an access token, as in
   [Start the server with an access token](#start-the-server-with-an-access-token).
2. Set `MIRLI_SANDBOXED=1` in the server's environment.
3. Restart the server.

The UI then offers nothing that touches the host, and settings that name a
path, a device, an engine or a URL are locked. To turn off only some of this,
set `MIRLI_DISABLE` instead. Both are described in
[Access control](https://mirli.app/docs/install-access/index.md#sandboxed-mode).

## What's next

- [Access control](https://mirli.app/docs/install-access/index.md)
- [Run Mirli in Docker](https://mirli.app/docs/install-docker/index.md)
- [Use another Mirli as an endpoint](https://mirli.app/docs/endpoints/index.md#use-another-mirli)
