Cheat sheet for the video [Devcontainers Explained: One File for Your Team, and the AI Catch](https://www.youtube.com/watch?v=T4D5Hy0F2SU) · [read the full page](https://kuzscotech.github.io/kush-exe/devcontainers-explained/)

## Where the file lives

In order of precedence:

- `.devcontainer/devcontainer.json`
- `.devcontainer.json` at the repo root
- `.devcontainer/FOLDER/devcontainer.json` (FOLDER is one level deep)

## Pick a base (one of three)

| Base | Keys |
| --- | --- |
| Prebuilt image | `image` |
| Your own Dockerfile | `build.dockerfile` |
| Docker Compose | `dockerComposeFile` plus `service` |

## The main keys

- `features`: shareable install units pulled from an OCI registry such as ghcr.io. Their `install.sh` runs as root while the image is built, so trust what you add.
- `customizations.vscode.extensions`: the VS Code extensions everyone gets (VS Code-specific).
- `forwardPorts`: ports that are always forwarded, for example `[3000, "db:5432"]`.
- `postCreateCommand`: runs once, when the container is first created.
- `remoteUser`: defaults to whatever user the container runs as, often root.

## Lifecycle hooks

- `initializeCommand`: runs on the host machine, not in the container.
- `onCreateCommand`, `updateContentCommand`, `postCreateCommand`: run in sequence, once, when the container is first created.
- `postStartCommand`: every time the container starts.
- `postAttachCommand`: every time a tool attaches.

## Add Claude Code with one Feature line

Under `features`:

```
ghcr.io/anthropics/devcontainer-features/claude-code:1.0
```

The `:1.0` tag pins the install script, not the Claude Code version.

## Open it in VS Code

- With Docker installed, open the repo and run `Dev Containers: Reopen in Container`.
- The first build takes a while; any edit to `devcontainer.json` or the Dockerfile means a rebuild.

## The doors to check before an agent runs free

- The workspace is a bind mount of your real repo: the agent can still change or delete any file in it.
- By default VS Code reuses your Git credentials and forwards your SSH agent if one is running.
- Anthropic's reference firewall is optional. Its default policy is DROP for INPUT, FORWARD and OUTPUT (`iptables -P INPUT DROP` and its siblings), but still allows GitHub, npm and outbound SSH on port 22.
- With `--dangerously-skip-permissions`, a dev container does not stop a malicious project from exfiltrating anything inside it, including the credentials in `~/.claude`.
- `--dangerously-skip-permissions` refuses to run as root, so use a non-root `remoteUser`.
- A VM, with its own kernel, is stronger isolation than a dev container.

## Safety checklist

- No `~/.ssh` and no cloud credentials mounted.
- Short-lived, repo-scoped tokens.
- Trusted repos only.

## Where it hurts

- On Mac and Windows, bind mounts are slower (for example during `yarn install`): use a named volume.
- Windows container images are not supported.
- On Alpine, some extensions may fail because of glibc dependencies.
- Docker Desktop needs a paid plan at companies with 250 or more employees or $10 million or more in annual revenue.
