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

# Dispersed Recipe Standard

> Container standard for Dispersed: non-root dispersed user, XDG directories, key-only SSH, token-gated HTTPS on port 8888, tag policy, and reproducible builds.

Version `1.0` defines how official Dispersed recipes and mirrors start, accept connections, and store files. You can also adopt it for a custom job. To pick a base and build your first image, see [Docker images](https://otoyinc.mintlify.site/service-consumers/docker-images.md).

## The standard at a glance

| Area | Requirement |
| - | - |
| Standard version | OCI label `com.dispersed.recipe-standard="1.0"` |
| Provenance | Official images and mirrors declare `org.opencontainers.image.title`, `org.opencontainers.image.description`, `org.opencontainers.image.source`, `org.opencontainers.image.base.name`, and `org.opencontainers.image.base.digest`. |
| Runtime identity | `USER dispersed` (name only), UID/GID `10000`, shell `/bin/bash`. No root processes, `sudo`, or setuid/setgid files. |
| Files | Work in `/home/dispersed`. Keep code under `/opt/<app>` read-only to the runtime user. |
| Startup | `tini` → `/usr/local/bin/dispersed-entrypoint.sh` → recipe `CMD` |
| Remote access | Optional key-only SSH on `22`; web recipes serve token-gated HTTPS on `8888`. |
| Reproducible builds | Pin the Debian or Ubuntu base by tag and digest. Install system packages from a shared, dated distribution snapshot. |

## Part 1: How standard recipes work

### Why the standard exists

Your job runs on an independent node operator's hardware. Running the app, SSH server, and web proxy without administrator privileges limits what a compromised process can change. A fixed user, file layout, and package snapshot also let you move workloads between recipes without changing paths or guessing which system packages a rebuild will install.

Every process runs as `dispersed` with UID and GID `10000`. The final Dockerfile user must be `USER dispersed`, without a group or numeric ID. Images remove `sudo` and strip setuid and setgid bits at build time. You can install user-level tools in your home directory; system packages and updates to `/opt/<app>` require a new image.

### Connect to a running job

Use the host and mapped port from your [Job Run Detail page](https://otoyinc.mintlify.site/service-consumers/service-consumers-quick-start-job-recipe.md#connect-to-the-running-container). Container ports `22` and `8888` describe the services inside the image; the external port can differ.

> [tab] SSH and file transfer
>
> When launching a recipe in the Console, select your key under **SSH Public Key**. For an API launch, set the Docker job parameter `sshkey`. Dispersed passes it to the container as `SSH_PUBKEY`. Allow your client's IP address in `allowed_ips`. Without a key, the entrypoint skips `sshd`. Only `dispersed` can log in; root login, passwords, and keyboard-interactive authentication are disabled. You can also transfer files with SFTP or SCP.
>
> The container generates an Ed25519 host key on first start and reuses it when the same container restarts.
>
> SSH sessions inherit the [five XDG directory variables](#filesystem-and-xdg-directories), `PATH`, `LD_LIBRARY_PATH`, and variables matching `NVIDIA_*`, `CUDA_*`, or `HF_*` from the workload environment. The filter excludes `SSH_PUBKEY`, `CONTAINER_ACCESS_TOKEN`, and names containing `TOKEN`, `SECRET`, `PASSWORD`, or `KEY`, even when a prefix matches.

> [tab] HTTPS and API clients
>
> Caddy checks the job's `CONTAINER_ACCESS_TOKEN` on port `8888`. For an API request, send `Authorization: Bearer <token>`. For Basic Auth, use `dispersed:<token>`; in a browser, enter `dispersed` as the username and the token as the password.
>
> Missing or incorrect credentials return `401 Unauthorized` with a Basic Auth challenge. Caddy strips the `Authorization` header before forwarding the request to your app on loopback. Basic Auth uses a bcrypt hash; the Bearer check reads the token from memory. Neither writes the plaintext token to disk.
>
> Caddy flushes server-sent events (`text/event-stream`) as they arrive. A client disconnect cancels the upstream request. The built-in `http_auth_healthcheck` sends an authenticated request through the proxy and accepts only `2xx` or `3xx`.

To generate a token for Caddy, add this entry to your Job Recipe's `input_schema` array:

```json theme={null}
{
  "key": "env.CONTAINER_ACCESS_TOKEN",
  "type": "container_access_token",
  "label": "Access token",
  "required": true
}
```

Dispersed generates the token when you cook the recipe. Every run of that job uses the same token. Cooking the recipe again creates a new job with a new token.

For a [standalone custom job](https://otoyinc.mintlify.site/service-consumers/service-consumers-create-job.md), set `CONTAINER_ACCESS_TOKEN` in the job's environment variables, include `8888` in `ports`, and allow your client's public IP range in `allowed_ips`.

A valid token is 16 to 72 ASCII characters matching `[A-Za-z0-9_-]{16,72}`. By default, Caddy refuses to start if the token is empty or malformed.

By default, Caddy generates a self-signed TLS certificate. To use your own, provide both `CADDY_TLS_CERT` and `CADDY_TLS_KEY`.

> [!WARNING]
>
> `ALLOW_UNAUTHENTICATED=true` disables authentication only when `CONTAINER_ACCESS_TOKEN` is empty. With a valid token, Caddy still requires credentials. With a malformed token, it still refuses to start. `CADDY_TLS=off` sends credentials over plain HTTP. Use these overrides only for isolated local debugging.

### Filesystem and XDG directories

| Path | Access at runtime | What belongs here |
| - | - | - |
| `/opt/<app>` | Root-owned, read-only to `dispersed` | Application code, binaries, bundled assets |
| `/home/dispersed` | Owned by `dispersed`, mode `0750` | Working directory, SSH landing directory, user files |
| `/tmp` | Writable scratch space | Temporary files |
| `/run/user/10000` | Owned by `dispersed`, mode `0700` | Sockets and PID files; cleared on startup |

> [!NOTE]
>
> Writes to the container filesystem under `/home/dispersed` are ephemeral. They do not persist across separate runs. Copy outputs you need out of the container before the run ends.

| XDG variable | Default path | Contents |
| - | - | - |
| `XDG_CONFIG_HOME` | `/home/dispersed/.config` | App settings and generated Caddyfile |
| `XDG_CACHE_HOME` | `/home/dispersed/.cache` | Rebuildable caches |
| `XDG_DATA_HOME` | `/home/dispersed/.local/share` | Models, outputs, uploads, TLS certificates |
| `XDG_STATE_HOME` | `/home/dispersed/.local/state` | Logs, databases, SSH host key and configuration |
| `XDG_RUNTIME_DIR` | `/run/user/10000` | Temporary runtime files; falls back to `/home/dispersed/.run` with a log message |

### Startup and shutdown

`tini` runs as PID 1, forwards shutdown signals, and reaps child processes. It starts `/usr/local/bin/dispersed-entrypoint.sh`, which:

1. Exports the XDG variables and creates their directories.
2. Clears the runtime directory, using the home-directory fallback if needed.
3. Starts `sshd` in the background when you supply `SSH_PUBKEY`.
4. Executes the image's `CMD`. When testing locally with `docker run`, you can override this command after the image name.

With no command, the container stays available over SSH if you supplied a key. Otherwise, it idles until stopped.

### Environment variables

| Variable | Set by | Effect |
| - | - | - |
| `SSH_PUBKEY` | Platform, from your launch input | Enables SSH using your public key or keys. Empty disables SSH. |
| `CONTAINER_ACCESS_TOKEN` | Platform or you | All runs of a job use the same token for port `8888`. Supply your own for standalone custom jobs and local tests. |
| `CADDY_TLS` | You | `internal` (default) for self-signed HTTPS; `off` for HTTP. |
| `CADDY_TLS_CERT`, `CADDY_TLS_KEY` | You | Supply absolute paths to both the PEM certificate and its matching private key. Use only ASCII letters, digits, `.`, `_`, `/`, and `-`. Neither path may contain a `..` component. |
| `ALLOW_UNAUTHENTICATED` | You | `true` permits unauthenticated access and logs a warning only when the token is empty. |
| `DISPERSED_CADDYFILE` | You or the recipe | Generated configuration path; defaults to `$XDG_CONFIG_HOME/dispersed/Caddyfile`. |
| `XDG_*` | Image | The five paths in [Filesystem and XDG directories](#filesystem-and-xdg-directories). |

### Supported operating systems

Use Debian `bookworm` or `trixie`, or Ubuntu `22.04` or `24.04`, with `apt` and `bash`. The username `dispersed` and UID/GID `10000` must be available or already identify the same account. Alpine, distroless, and `scratch` images do not support this standard.

### Official images

> [accordion] Supported public base images
>
> `dispersednetwork/base` provides Ubuntu 24.04 and key-only SSH for CLI workloads. `dispersednetwork/basic-auth` extends it with Caddy for web workloads. These are the two officially supported public bases for building your own recipe.

> [accordion] Public catalog recipes
>
> | Recipe | Image | Services |
> | - | - | - |
> | ComfyUI | `dispersednetwork/comfyui` | HTTPS and SSH |
> | ComfyUI (CUDA 13.0) | `dispersednetwork/comfyui-cuda13.0` | HTTPS and SSH |
> | llama.cpp Server | `dispersednetwork/llama-cpp` | HTTPS and SSH |
> | PyTorch 2.10.0 (CUDA 13.0) | `dispersednetwork/pytorch-2.10.0-cuda13.0-cudnn9-devel` | SSH |

> [accordion] Official mirrors
>
> Mirrors include `dispersednetwork/ubuntu:24.04`, `dispersednetwork/debian:trixie`, `dispersednetwork/pytorch-pytorch`, `dispersednetwork/nvidia-cuda`, `dispersednetwork/nvidia-pytorch`, and `dispersednetwork/chromadb-chroma`.
>
> Mirrors retain upstream files, environment variables, labels, and exposed-port metadata. Their provenance labels identify the upstream base and digest. Mirrors **replace the upstream entrypoint** and idle under SSH when you supply a key. To start the upstream app automatically on Dispersed, build a child image with the app's startup command as its `CMD`. For an interactive job, start the app from your SSH session.

### Upgrading from previous recipes

A running job keeps its image until it stops. Check scripts and paths before your next run on Standard `1.0`.

| Update | Previous recipes | Standard `1.0` |
| - | - | - |
| SSH and Basic Auth username | `duser` | `dispersed` |
| HTTP credentials | Basic Auth only | Basic Auth or `Authorization: Bearer <token>` |
| System package installation | `sudo` at runtime | No `sudo`; install packages at build time |
| ComfyUI models, inputs, outputs, and settings | Under `/opt/comfyui/` | Under `~/.local/share/comfyui/` |

### Known limits

* If the non-root SSH server cannot bind port `22`, as can happen with host networking, the app continues without SSH. Starting the container with `--user 0` also disables SSH.
* You cannot install system packages in an SSH session or let an app update its own files in `/opt`. Write to your home, `/tmp`, or `XDG_RUNTIME_DIR`.
* New package layers can reintroduce setuid or setgid files. Strip these bits again in each installation layer.

## Part 2: Build your own image

Start with Docker and one of the two public bases: `dispersednetwork/base` for CLI jobs or `dispersednetwork/basic-auth` for HTTP workloads. Both provide the runtime user, directories, SSH setup, and entrypoint.

### Choose a tag

| Image family | Tags | How to choose |
| - | - | - |
| Supported bases | `v1`, `v1.0`, `v1-YYYYMMDD`, `latest` | Use `v1` to track the major version, `v1.0` for the standard's minor version, or a dated tag for a specific package snapshot. `latest` follows the current release. |
| Application recipes and mirrors | Moving tag plus immutable content-hash tag | Use `latest` or the upstream tag (such as `24.04`) to follow releases. Select the content-hash tag to reuse the same image. |
| Release candidates in either family | `rc`, `<tag>-rc` | Pre-release builds for verification. |

Dispersed records the resolved digest when you create a job. Nodes can still pull by tag, so a retry can use a different image if the tag moves. Choose an immutable content-hash tag when every run must use the same image.

### Example 1: Serve a static site

Place `index.html` beside your `Dockerfile`. Caddy serves the file on port `8888` using the base image's authentication and health check.

```dockerfile Dockerfile theme={null}
# syntax=docker/dockerfile:1
FROM dispersednetwork/basic-auth:v1
COPY --chown=root:root --chmod=0644 index.html /opt/basic-auth/public/index.html
```

### Example 2: Run a web app behind Caddy

In a new directory, save the following three files. The sample Node.js API listens only on `127.0.0.1:3000`. Caddy is the only public web listener.

```javascript server.js theme={null}
const http = require("node:http");

http.createServer((_request, response) => {
  response.writeHead(200, { "Content-Type": "application/json" });
  response.end(JSON.stringify({ status: "ready" }));
}).listen(3000, "127.0.0.1");
```

Generate the proxy configuration **before** starting the app. Give only Caddy the token, then stop both processes if either exits or the container receives a termination signal.

```bash start.sh theme={null}
#!/usr/bin/env bash
set -euo pipefail
source /usr/local/lib/dispersed-http-auth.sh
generate_caddyfile 127.0.0.1:3000 || exit 1

env -u CONTAINER_ACCESS_TOKEN node /opt/status-api/server.js &
app_pid=$!
caddy run --config "$DISPERSED_CADDYFILE" --adapter caddyfile &
proxy_pid=$!

stop_children() {
  trap '' TERM INT
  kill -TERM "$app_pid" "$proxy_pid" 2>/dev/null || true
  local deadline=$((SECONDS + 8))
  while kill -0 "$app_pid" 2>/dev/null || kill -0 "$proxy_pid" 2>/dev/null; do
    if (( SECONDS >= deadline )); then
      kill -KILL "$app_pid" "$proxy_pid" 2>/dev/null || true
      break
    fi
    sleep 0.1
  done
  wait "$app_pid" "$proxy_pid" 2>/dev/null || true
}
trap stop_children EXIT
trap 'exit 0' TERM INT
status=0
wait -n "$app_pid" "$proxy_pid" || status=$?
exit "$status"
```

```dockerfile Dockerfile theme={null}
# syntax=docker/dockerfile:1
FROM dispersednetwork/basic-auth:v1@sha256:5df3555577715d1c5c84b5ae3e6c9134a10a2a93f63df212cb50fa79fece5b5a
USER root
RUN snapshot="$(cat /usr/local/share/dispersed/apt-snapshot)" \
    && printf '%s\n' \
        'Types: deb' \
        "URIs: https://snapshot.ubuntu.com/ubuntu/${snapshot}/" \
        'Suites: noble noble-updates noble-security' \
        'Components: main universe' \
        'Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg' \
        'Check-Valid-Until: no' > /etc/apt/sources.list.d/ubuntu.sources \
    && apt-get update --error-on=any \
    && apt-get install -y --no-install-recommends nodejs \
    && rm -rf /var/lib/apt/lists/* \
    && find / -xdev -type f -perm /6000 -exec chmod u-s,g-s {} + \
    && install -d -m 0755 /opt/status-api
USER dispersed
COPY --chown=root:root --chmod=0644 server.js /opt/status-api/server.js
COPY --chown=root:root --chmod=0755 start.sh /opt/status-api/start.sh
CMD ["/opt/status-api/start.sh"]
LABEL com.dispersed.recipe-standard="1.0"
```

> [!NOTE]
>
> The digest pins the base image. Apt installs Node.js and its dependencies from that image's recorded Ubuntu snapshot. It verifies the archive signature but allows historical metadata past its expiry date.

### Rules for child images

* Keep `USER dispersed`, `WORKDIR /home/dispersed`, and the inherited `ENTRYPOINT`. To change the launch command, set `CMD`.
* Install code as `root:root` under `/opt/<app>` without write permission for the runtime user. Write app data, configuration, caches, and state to the corresponding XDG directories.
* Install extra system packages as root **during the build**. In the same `RUN`, strip setuid and setgid bits, as in Example 2. Switch back to `USER dispersed`.
* Bind your app to loopback. Do not expose its internal port. Remove `CONTAINER_ACCESS_TOKEN` from the app environment and supervise the app and Caddy together.
* Keep or add `LABEL com.dispersed.recipe-standard="1.0"` for a conforming image. Put new labels last so label edits preserve the package-layer cache.

> [!TIP]
>
> If `/` does not return `2xx` or `3xx`, point the Docker health check at your app's health route. For example, add `HEALTHCHECK CMD bash -c 'source /usr/local/lib/dispersed-http-auth.sh && http_auth_healthcheck /health'`.

### Test locally

From either web example's directory, use Docker with `linux/amd64` support, OpenSSL, curl, and an SSH key pair. Adjust the key path if needed. Run these commands in the same terminal:

```bash theme={null}
docker build --platform linux/amd64 -t dispersed-web-test .
export CONTAINER_ACCESS_TOKEN="$(openssl rand -hex 24)"
docker run --detach --rm --platform linux/amd64 --name dispersed-web-test \
  -p 127.0.0.1:8888:8888 -p 127.0.0.1:2222:22 \
  -e CONTAINER_ACCESS_TOKEN \
  -e SSH_PUBKEY="$(cat ~/.ssh/id_ed25519.pub)" \
  dispersed-web-test
```

After startup, the first request should print `401`. Both authenticated requests should return your site or JSON. Here `-k` accepts the local container's self-signed certificate.

```bash theme={null}
curl -ks -o /dev/null -w '%{http_code}\n' https://localhost:8888/
printf 'header = "Authorization: Bearer %s"\n' "$CONTAINER_ACCESS_TOKEN" | curl -fk -K - https://localhost:8888/
printf 'user = "dispersed:%s"\n' "$CONTAINER_ACCESS_TOKEN" | curl -fk -K - https://localhost:8888/
known_hosts="$(mktemp)"
ssh -o UserKnownHostsFile="$known_hosts" -o StrictHostKeyChecking=accept-new \
  -i ~/.ssh/id_ed25519 -p 2222 dispersed@localhost 'id -un'
rm -f "$known_hosts"
docker stop dispersed-web-test
unset CONTAINER_ACCESS_TOKEN
```

The SSH command should print `dispersed`. Stopping this test container removes its writable filesystem because it started with `--rm`.


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