hack.foo
Guides

Codespaces and dev containers

Dev container: verified on 2026-11-19 with the Dev Container CLI 0.90.0 on Linux x86_64 and hack built from next at 6447491b33. devcontainer up with the files then committed started the project with no other command. That run's install script copied in the built binary; the release installer shown below was not part of it.

GitHub Codespaces: not run yet. It reads the same devcontainer.json.

What you need

  • A repository with a working .hack/ folder.
  • For Codespaces: a GitHub account that can create codespaces on the repository. Locally: Docker and the Dev Container CLI or an editor that supports dev containers.
  • If the project has encrypted values: its key, stored as a secret named HACK_ENV_SECRET_KEY.

Files to commit

.devcontainer/devcontainer.json:

{
  "name": "hack project",
  "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04",
  "features": {
    "ghcr.io/devcontainers/features/docker-in-docker:2": {}
  },
  "remoteUser": "vscode",
  "containerEnv": {
    "HACK_NO_INTERACTIVE": "1"
  },
  "remoteEnv": {
    "PATH": "${containerEnv:PATH}:${containerEnv:HOME}/.hack/bin"
  },
  "onCreateCommand": "sh .devcontainer/install-hack.sh",
  "postStartCommand": "hack config set --global proxy.bind_address 127.0.0.1 && hack global install --no-interactive && hack up --detach --no-interactive --json"
}

The docker-in-docker feature gives the container its own Docker Engine and Compose. postStartCommand runs on every start, so the project comes back after a stop.

.devcontainer/install-hack.sh installs hack with the release installer into ~/.hack/bin, which remoteEnv adds to PATH. The release archive includes hack-lifecycle-supervisor. A project with lifecycle processes also needs tmux (see Any Linux machine with Docker).

#!/bin/sh
set -eu
curl -fsSL https://github.com/hack-dance/hack/releases/latest/download/hack-install.sh | HACK_INSTALL_NONINTERACTIVE=1 bash
"$HOME/.hack/bin/hack" --version

The installer also runs hack global install once, with the proxy on every interface; postStartCommand moves it to loopback.

The key is not in the file. In Codespaces, add HACK_ENV_SECRET_KEY as a Codespaces secret for the repository (Settings → Secrets and variables → Codespaces → New repository secret); Codespaces gives it to the container's processes, including postStartCommand. Locally, the Dev Container CLI does the same with --secrets-file, a JSON file such as {"HACK_ENV_SECRET_KEY": "..."} kept outside the repository with mode 0600. devcontainer up runs the checkout's onCreateCommand, postStartCommand and install script with that key, so pass --secrets-file only for a checkout you have reviewed (a contributor's branch can change those files to send the key out). Codespaces does not give repository secrets to a codespace created from a pull request branch in a fork (see GitHub's security in Codespaces).

Start it

Locally (verified):

devcontainer up --workspace-folder . --secrets-file <secrets-file>

In Codespaces (not run yet): create a codespace on the branch; postStartCommand should start the project.

Check it

In the container's terminal (use your project's host):

curl --noproxy hello.hack.local --resolve hello.hack.local:443:127.0.0.1 -k https://hello.hack.local/

In the verified run, devcontainer up started the project. The key came from --secrets-file, the page printed token-present, and the key did not appear in the CLI's output.

What is different from a laptop

  • Addresses. The container has no DNS for Hack's names. Use curl --resolve inside it, or the hack open hint, which prints the same form. A Codespaces forwarded port (https://<name>-<port>.app.github.dev) sends its own host name, and Hack's proxy has no route for it yet, so forwarding 443 does not show the app.
  • Secrets. Codespaces secrets are environment variables in the container. Anyone with access to the codespace can read them.
  • Persistence. The docker-in-docker feature keeps Docker's data (/var/lib/docker: images, volumes, stopped containers) in a Docker volume, so it survives a stop and a rebuild. A rebuild replaces the container's own filesystem and runs onCreateCommand again.

What does not work yet

  • The release installer has not been run in a dev container; the verified run used a hack built from source.
  • Browser preview through forwarded ports (see Addresses).

Source: v5 (next.34) · docs/site/guides/cloud-dev-containers.md.

On this page