# Self-host Aglio

Aglio ships a free self-host bundle: public container images, a pull-only
Compose file and a generated `.env`. There is no source checkout, no source
tarball and no public Git mirror. The images are licensed under
[PolyForm Shield 1.0.0](../LICENSE), which permits self-hosting but forbids
running Aglio as a competing hosted service.

- License: https://aglio.xyz/license
- Installer, Compose and helper downloads: https://aglio.xyz/self-host
- Release history: [changelog](https://aglio.xyz/changelog.md), also under
  **Help -> Changelog** in the app

## Requirements

- A 64-bit Linux host with Docker Engine 24+ and the Docker Compose plugin.
  Published images run on x86_64 and arm64 hosts.
- 2 vCPU, 4 GB RAM and 20 GB free disk for the web app, Postgres and a small
  workspace. Agent runs need more disk for their toolchains.
- Outbound HTTPS for image pulls, GitHub, model providers and optional email.
- Port 3000 free, or set `AGLIO_PORT`. Put a TLS reverse proxy in front for a
  public domain and forward `X-Forwarded-For`.
- Optional: a GitHub App/PAT, a model provider key and an SMTP/Resend endpoint.
  Aglio starts and the first owner can sign up without any of them.

Supported images, published for every release tag:

| Image | Purpose |
| --- | --- |
| `ghcr.io/h4kbas/aglio-web` | Web app and in-process scheduler |
| `ghcr.io/h4kbas/aglio-migrate` | Applies database migrations once per start |
| `ghcr.io/h4kbas/aglio-worker` | Machine agent for job runs |
| `ghcr.io/h4kbas/aglio-runner` | Sandbox image started by an agent |
| `ghcr.io/h4kbas/aglio-runner-node` | Node.js and Bun development image |
| `ghcr.io/h4kbas/aglio-runner-python` | Python development image |
| `ghcr.io/h4kbas/aglio-runner-rust` | Rust development image |
| `ghcr.io/h4kbas/aglio-runner-go` | Go development image |
| `ghcr.io/h4kbas/aglio-runner-java` | Java development image |
| `ghcr.io/h4kbas/aglio-runner-ruby` | Ruby development image |
| `ghcr.io/h4kbas/aglio-runner-php` | PHP development image |
| `ghcr.io/h4kbas/aglio-runner-dotnet` | .NET development image |

Pin a release such as `v0.115.11` or the immutable digest. `:master`, `:latest`
and `:input-<hash>` are internal tags; do not use them for a self-hosted install.

Runs use your own enrolled workers. Cloud runner targets, hosted billing and the
platform `/admin` portal are SaaS-only and are hidden or return 404 when
`AGLIO_SELFHOST=1`. `Auto` means your workers only on a self-hosted install.

## One-command install

On a fresh machine with Docker only:

```bash
curl -fsSL https://aglio.xyz/self-host/install.sh | bash -s -- v0.115.11
cd aglio && docker compose -f docker-compose.selfhost.yml up -d
```

The installer writes `docker-compose.selfhost.yml`, `backup.sh`, `restore.sh`
and a private `.env` with generated `BETTER_AUTH_SECRET`, `AGLIO_SECRET_KEY`
and `POSTGRES_PASSWORD`. It never writes into a source tree and the Compose file
uses named volumes only. Non-secret answers can be passed as flags or
environment variables instead of editing `.env` by hand:

```bash
curl -fsSL https://aglio.xyz/self-host/install.sh | bash -s -- v0.115.11 \
  --port 8080 --url https://aglio.example.com --worker-dir /srv/aglio-worker
```

The same values are read from `AGLIO_PORT`, `NEXT_PUBLIC_APP_URL`,
`AGLIO_SELFHOST_DIR` and `AGLIO_WORKER_HOST_DATA_DIR`. The installer creates the
worker data directory and its `workspaces` subdirectory owned by `1000:1000`,
and writes the detected Docker socket group to `DOCKER_GID`. When it cannot
create the directory as the current user it prints the exact `sudo` command to
run once.

Open `http://<host>:3000/api/health`; it answers `{"ok":true}`. Then open
`http://<host>:3000`, choose **Create account**, and the first sign-up becomes
the workspace owner. The sign-in page stays open to anyone who can reach it:
every later account needs an invite token from the owner before it can join the
workspace.

The installer also writes a `CRON_SECRET`, so the web process runs the
in-process scheduler that drives auto-claim, auto-mode, GitHub polling,
recovery, retention and notifications. Leave it in place unless an external
scheduler calls `/api/cron/*` itself; in that case set `AGLIO_INPROCESS_CRON=0`
in `.env` and give the scheduler the same secret.

### Install with an AI agent

The install wizard on https://aglio.xyz/self-host also builds a copyable prompt
with your answers filled in. Paste it into Claude Code, Codex or another
terminal agent on the target host when you would rather review an agent's
install than run each command yourself. The prompt below is the same shape with
placeholders:

```text
You are installing Aglio on this machine from the public self-host bundle.
Work in a shell on the target host and finish with a working, verified install.

Configuration:
- Release: <release, for example v0.115.11>
- Public origin: <origin, for example https://aglio.example.com>
- Web port: <port, for example 3000>
- Install directory: <install dir, for example aglio>
- Agent worker: <enabled at /srv/aglio-worker, or not enabled>

Steps:
1. Check prerequisites: Docker Engine 24+, the Docker Compose plugin, curl and
   openssl. Check that the web port is free. If something is missing, stop and
   report it. Do not install Docker, change firewall rules or change DNS.
2. Run the installer from the directory where the install directory should
   live:
   curl -fsSL https://aglio.xyz/self-host/install.sh | \
     AGLIO_SELFHOST_DIR=<install dir> bash -s -- <release> \
     --port <port> --url <origin>
   It downloads a pull-only Compose file, backup and restore helpers, and writes
   a private .env with generated secrets.
3. Start the stack:
   cd <install dir> && docker compose -f docker-compose.selfhost.yml up -d
4. Wait for the stack to become healthy:
   curl -fsS http://localhost:<port>/api/health?db=1
   Retry for up to two minutes. If it never becomes healthy, inspect
   `docker compose -f docker-compose.selfhost.yml ps` and the migrate and web
   logs.
5. Report the install directory, public origin, health check result and the next
   step: open <origin> and create the first account. That account becomes the
   workspace owner; later sign-ups need an invite.

Rules:
- Do not print, copy or commit the generated secrets from .env.
- Do not edit docker-compose.selfhost.yml; put non-secret changes in .env.
- Never run `docker compose ... down -v`; it deletes the database and artifact
  volumes.
- Do not expose Postgres, the Docker socket or the install directory over the
  network.
- An https origin needs DNS pointing at this host and a TLS reverse proxy in
  front of the web port. Stop and ask before changing either.
```

If the worker is enabled, add: after the first account exists, ask the workspace
owner for an enrollment token from **Settings > Workers**, write it to `.env` as
`AGLIO_WORKER_TOKEN` without echoing it, make sure the worker directory and its
`workspaces` subdirectory are owned by `1000:1000`, then run
`docker compose -f docker-compose.selfhost.yml --profile worker up -d worker`.

Review the agent's report before you rely on the install. The generated secrets
stay in `.env`; do not paste them into the chat.

### Configure the public URL

Edit `.env` before the first start (or restart web afterwards):

```dotenv
NEXT_PUBLIC_APP_URL=https://aglio.example.com
AGLIO_APP_URL=https://aglio.example.com
BETTER_AUTH_URL=https://aglio.example.com
```

`AGLIO_APP_URL` is read at runtime by the web container (Compose sets it from
`NEXT_PUBLIC_APP_URL`), so canonical links and the sitemap use your host even
though the public image was built for Aglio's own site. Keep `BETTER_AUTH_URL`
identical. Changing the host later requires a restart and a fresh login.

## Pin a version

`.env` holds the pin used by every service and by the runner image:

```dotenv
AGLIO_TAG=v0.115.11
```

For stronger immutability, prefer a digest from the package page, for example
`ghcr.io/h4kbas/aglio-web@sha256:...`. Change `AGLIO_TAG` in one place; do not
edit the Compose file. Releases are listed in the
[changelog](https://aglio.xyz/changelog.md) and on the public package pages:
<https://github.com/h4kbas/aglio/pkgs/container/aglio-web>.

The install wizard on the website defaults to the release tag the web image was
built from. CI passes every `v*` tag as the `AGLIO_VERSION` build arg, so the
wizard and the worker version badge read the same value and no checklist step
can leave them behind. The wizard never fetches tags, because the source
repository is private.

## Upgrade

1. Read the [changelog](https://aglio.xyz/changelog.md) for the target release.
2. Take a backup: `./backup.sh`.
3. Set the new tag in `.env`, for example `AGLIO_TAG=v0.115.11`.
4. Pull and restart. The `migrate` service runs before web starts:

   ```bash
   docker compose -f docker-compose.selfhost.yml pull
   docker compose -f docker-compose.selfhost.yml up -d
   ```

5. Check `curl -fsS http://localhost:3000/api/health?db=1` and sign in.
6. To roll back, set the previous tag and run the same two commands. Migrations
   are additive-only, so a rollback does not need a database restore unless the
   release notes say otherwise.

## Backup and restore

`backup.sh` dumps Postgres, the schema and the artifact volume, writes
`SHA256SUMS`, and stores everything under `backups/aglio-<UTC timestamp>`.
`restore.sh` verifies the checksums, replaces the current database contents with
the dump and stops on the first SQL error.

```bash
./backup.sh
./restore.sh backups/aglio-20261130T101500Z
```

Run both from the install directory. If the stack is down, export `DATABASE_URL`
and the scripts fall back to a direct `pg_dump`/`psql`. The default retention is
manual: copy `backups/` off the host (object storage, another disk) and prune old
directories yourself.

`docker compose down` keeps the `aglio_pgdata` and `aglio_appdata` volumes.
`docker compose down -v` deletes both and is not part of an upgrade.

## Reset a password

With `RESEND_API_KEY` and `EMAIL_FROM`, **Forgot your password?** on the sign-in
page emails a one-hour reset link. Without email, that page points to the owner
recovery below, which prints a one-time reset link from the migrate image:

```bash
docker compose -f docker-compose.selfhost.yml run --rm \
  --entrypoint pnpm migrate \
  --filter @aglio/worker reset-password owner@example.com
```

Open the printed link on the same host within its lifetime and set a new
password. The command never prints or changes the old password. See
[password-recovery.md](./password-recovery.md).

## Run jobs (optional agent)

The default bundle runs web, migrations and Postgres. To let an agent build
cards, create an enrollment token in **Settings > Workers**. For the default
path, the installer creates `/srv/aglio-worker` and `/srv/aglio-worker/workspaces`
owned by `1000:1000`. If it printed a `sudo` line, run that once. For a custom
location, use an absolute path and create both directories before starting the
profile:

```bash
sudo mkdir -p /srv/aglio-worker/workspaces
sudo chown 1000:1000 /srv/aglio-worker /srv/aglio-worker/workspaces
```

Then set the token and path in `.env` and start the optional agent service:

```dotenv
# .env
AGLIO_WORKER_TOKEN=<enrollment token>
AGLIO_WORKER_HOST_DATA_DIR=/srv/aglio-worker
```

```bash
docker compose -f docker-compose.selfhost.yml --profile worker up -d worker
```

The worker advertises the `tools:node` label by default. A project that requires
another `runner:<type>` label only matches a worker that advertises it, so list
every development image the machine should serve, using the same ids as the
image picker in **Settings > Workers**:

```dotenv
# .env
AGLIO_WORKER_LABELS=tools:node,runner:python,runner:rust
```

Images are pulled on the first job that needs them, so start with the languages
your projects use. Without a `runner:` label a job runs in the general image,
which carries the full toolchain.

The installer writes `DOCKER_GID` from the Docker socket group instead of
guessing. Re-check it after a Docker reinstall and update `.env`:

```bash
DOCKER_GID=$(stat -c '%g' /var/run/docker.sock)  # macOS/BSD: stat -f '%g'
```

On Docker Desktop and OrbStack the socket is `root:root` inside the container
whatever its host group, so set `DOCKER_GID=0` there instead of the host group.

The agent mounts the host Docker socket to start sibling `aglio-runner`
containers; the runner never receives the control-plane database credentials or
workspace secrets. The same setup works on a separate desktop or Linux host with
`docker-compose.byow.yml` from an Aglio checkout. Keep the agent image tag equal
to `AGLIO_TAG`.

## GitHub integration

Every project needs a GitHub or GitLab credential. The shortest path is a
fine-grained GitHub PAT or a GitLab token pasted into the project settings. A
GitHub App is optional and shared by the whole install: set `GITHUB_APP_ID`,
`GITHUB_APP_PRIVATE_KEY`, `GITHUB_APP_WEBHOOK_SECRET` and `GITHUB_APP_SLUG` in
`.env`, point the app's webhook URL at `<origin>/api/github/webhook` and its
setup URL at `<origin>/api/github/setup`, and subscribe to pull request, review,
review comment, issue comment and check events. Webhook deliveries arrive in
seconds; the in-process GitHub polling stays on as the fallback for PAT projects
and missed deliveries.

## Troubleshooting

- **Web restarts with a schema error**: `migrate` did not finish. Run
  `docker compose -f docker-compose.selfhost.yml logs migrate` and re-run
  `up -d`.
- **Login redirects to the wrong host**: `BETTER_AUTH_URL` and
  `NEXT_PUBLIC_APP_URL` must be the same public origin, including scheme.
- **Images fail with `denied`**: the GHCR packages are public; check the tag in
  `.env` exists on the package page, then `docker compose ... pull`.
- **Password email never arrives**: set `RESEND_API_KEY` and `EMAIL_FROM`, or use
  the reset link command above.
- **Agent cannot start runners**: `DOCKER_GID` must match the socket group and
  `AGLIO_WORKER_HOST_DATA_DIR` must be an absolute host path. The worker row on
  Settings -> Workers shows the agent's own check of the socket, runner images,
  workspace and disk, with the command that fixes the failing one.

## License and support

The bundle is source-available, not open source. It is licensed under PolyForm
Shield 1.0.0: self-host it for your team, but do not run it as a product that
competes with Aglio. See [LICENSE](../LICENSE) or https://aglio.xyz/license.

Self-hosting includes no warranty and no support entitlement. Support is
available only through the paid Aglio plans; the license terms govern use of the
software. The [terms of service](https://aglio.xyz/terms) cover both the hosted
service and the self-hosted bundle.
