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

> ## Agent Instructions
> These docs describe the Ancha CLI, npm package @ancha-labs/cli version 0.1.4, and the hosted workspace at app.ancha.io. Coding agents should start at https://docs.ancha.io/coding-agents. Run the CLI as `ancha` after `npm install -g @ancha-labs/cli`, or as `npx -y @ancha-labs/cli@0.1.4` without installing. Pass --json for machine-readable output, or set ANCHA_JSON=1. Every command ends with a `next:` line naming the next command. Exit codes: 0 pass, 1 a check failed or a comparison regressed, 2 usage, config or authentication error, 3 infrastructure error, 4 unimplemented endpoint with --strict.

# ancha serve

> Run an Ancha server in the foreground so environments, sandboxes and the local console can share it. Stops on Ctrl-C.

`ancha serve` runs an Ancha server until you stop it with Ctrl-C or SIGTERM. `ancha run` and `ancha doctor` start their own server when none is configured, so you only need `serve` to share one server between commands: `ancha env`, `ancha sandbox`, `ancha mcp` and `ancha ui --server-url`.

```bash theme={null}
ancha serve [options]
```

| Option | Description |
| - | - |
| `--port <n>` | Port to listen on, 0 for any free port (default: 4400) |
| `--host <host>` | Address to bind (default: "127.0.0.1") |
| `--public-url <url>` | Advertised HTTP loopback origin (match the Docker host port) |

## Example

```bash theme={null}
ancha serve
```

```text Output theme={null}
ancha server listening on http://127.0.0.1:4400
press Ctrl-C to stop
```

In another terminal, point commands at it. `http://127.0.0.1:4400` is already the default for server commands:

```bash theme={null}
ancha sandbox create --preset operations
ancha ui --server-url http://127.0.0.1:4400
```

`--port 0` picks a free port. The server binds `127.0.0.1` by default.

## Running it in Docker

Inside a container, bind all interfaces and advertise the host-side address, so the URLs it hands out work from your machine:

```bash theme={null}
ancha serve --host 0.0.0.0 --port 4400 --public-url http://127.0.0.1:14400
```

`--public-url` must be a loopback HTTP origin without credentials. It changes the URLs the server advertises, not the bind address.

Environments and sandboxes live in the server's memory and end when it stops.


## Related topics

- [ancha env](https://docs.ancha.io/cli/env.md)
- [ancha ui](https://docs.ancha.io/cli/ui.md)
- [ancha sandbox](https://docs.ancha.io/cli/sandbox.md)
- [CLI overview](https://docs.ancha.io/cli/overview.md)
- [ancha mcp](https://docs.ancha.io/cli/mcp.md)


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