# Run Sesh in Docker

> Run Sesh and your coding agents in a container on any computer with Docker, and drive them from Sesh on your Mac, iPhone, iPad, Android or Linux.

Source: https://sesh.codes/docs/docker/

Sesh's images, [`ghcr.io/sesh-codes/sesh`](https://github.com/sesh-codes/docker), turn a container into a machine your agents work on. Run one on a home server, a NAS, a cloud server or your own computer. The agents can only change what's inside the container, and you can throw it away and start again.

## Before you start

- Docker on the computer, with Linux containers: Docker Engine on Linux, Docker Desktop on a Mac or Windows, or anything that runs Docker images. Intel and ARM both work.
- Sesh on your Mac, iPhone, iPad, Android phone or Linux computer, to pair it with.

## Pick an image

Each tag is Sesh plus one agent, ready to sign in to. Every image also has git, the GitHub CLI (`gh`), curl and ssh.

| Tag | Agent |
|---|---|
| `ghcr.io/sesh-codes/sesh:claude` | Claude Code |
| `ghcr.io/sesh-codes/sesh:codex` | Codex |
| `ghcr.io/sesh-codes/sesh:gemini` | Gemini CLI |
| `ghcr.io/sesh-codes/sesh:cursor` | Cursor |
| `ghcr.io/sesh-codes/sesh:opencode` | OpenCode (works without an account on its free models) |
| `ghcr.io/sesh-codes/sesh:all` | All five |
| `ghcr.io/sesh-codes/sesh:latest` | None yet: get agents from Sesh (see [Add more agents](#add-more-agents)) |

Each also comes pinned to a release, such as `ghcr.io/sesh-codes/sesh:0.47.0-claude`. The commands below use `claude`; swap in the tag you want.

## Start it

Pick one of the two ways below. Both keep everything worth keeping in a volume called `sesh-home`, and start Sesh again when Docker or the computer restarts.

**With `docker run`:**

```sh
docker run -d --name sesh --hostname my-sesh --restart unless-stopped \
  --security-opt seccomp=unconfined \
  -p 4777:4777/udp \
  -v sesh-home:/home/sesh \
  ghcr.io/sesh-codes/sesh:claude
```

**With Docker Compose**, save this as `compose.yaml`, then run `docker compose up -d` in its folder:

```yaml
services:
  sesh:
    image: ghcr.io/sesh-codes/sesh:claude
    hostname: my-sesh
    restart: unless-stopped
    security_opt:
      - seccomp=unconfined
    ports:
      - "4777:4777/udp"
    volumes:
      - sesh-home:/home/sesh

volumes:
  sesh-home:
```

What each part is for:

- **`--hostname`** is the name Sesh shows for the machine. Without it, the container's ID shows instead.
- **`--security-opt seccomp=unconfined`** lets Sesh sandbox [Autonomous sessions](https://sesh.codes/docs/approvals-and-autonomous.md) inside the container. See [The sandbox](#the-sandbox) to leave it out.
- **`-p 4777:4777/udp`** is optional. Sesh reaches the container from anywhere without it. It lets devices on the same network connect straight to it instead of going through Sesh's relay, which is a little faster.
- **`-v sesh-home:/home/sesh`** keeps your projects, sessions, pairings and sign-ins in a volume. Leave it out and they're lost when the container is removed.

## Pair it

Get a pairing code from the container:

```sh
docker exec -it sesh sesh pair
```

With Docker Compose, that's `docker compose exec sesh sesh pair`. It prints the machine's **ID** and a **Pairing code** that works once, for 10 minutes, and a QR code if the window is big enough.

- **On a Mac:** **Settings › Machines › Add Machine…**, paste the **ID** into **Machine**, enter the **Pairing code**, and click **Pair**.
- **On an iPhone or iPad:** tap **Add Machine** and scan the QR code.

The container shows up as **Connected**. More detail is in [Add a machine](https://sesh.codes/docs/add-a-machine.md#pair-it-with-sesh).

## Sign in

1. In **Settings › Machines**, click **Details…** next to the container.
2. Click the agent, then pick a way to sign in from its **Account** menu.

The sign-in page opens on the device you're using, even though the agent runs in the container. Sign-ins are saved in the volume, so you only do this once.

You can also sign in from a terminal in the container, such as `docker exec -it sesh claude`, then `/login`.

> **Using an API key instead?** Pass it when you start the container, for example `-e ANTHROPIC_API_KEY=…` for Claude Code, `OPENAI_API_KEY` for Codex, `GEMINI_API_KEY` for Gemini CLI or `CURSOR_API_KEY` for Cursor. Or use **Provide an API Key…** in the agent's **Account** menu.

## Give agents what they need

1. **Sign in to GitHub,** so agents can clone private repositories and push:

   ```sh
   docker exec -it sesh gh auth login
   ```

2. **Set your git name and email,** for the agents' commits:

   ```sh
   docker exec sesh git config --global user.name "Your Name"
   docker exec sesh git config --global user.email you@example.com
   ```

3. **Add your projects.** Clone them in a terminal on the container (**File › New Terminal on** and pick it), or ask an agent to. Projects in `~/code` show up in **New Session** on their own.

Dev servers that agents start in the container open on your devices like local ones, with no ports to publish. See [Dev servers](https://sesh.codes/docs/dev-servers.md).

### Add your project's tools

The images have no compilers, language runtimes or databases besides Node.js (in the Claude Code, Codex, Gemini CLI and `all` images). Agents can't install system packages, since they don't run as root. To add tools, build your own image on top of Sesh's. Save this as `Dockerfile`:

```dockerfile
FROM ghcr.io/sesh-codes/sesh:claude
USER root
RUN apt-get update && apt-get install -y --no-install-recommends \
      build-essential python3 \
 && rm -rf /var/lib/apt/lists/*
USER sesh
```

Then build it with `docker build -t my-sesh .` and use `my-sesh` in place of `ghcr.io/sesh-codes/sesh:claude`. With Docker Compose, replace the `image:` line with `build: .` and run `docker compose up -d --build`.

## Add more agents

Any image can run more agents. In the container's **Details…**, click **Get** next to an agent, or **Add an Agent…** for one from the [ACP Registry](https://sesh.codes/docs/more-agents.md). Agents added this way are saved in the volume, so they stay when the image is updated.

## The sandbox

Autonomous sessions run sandboxed: the agent can change only the session's own folder, and can't read SSH keys or sign-ins. The sandbox needs something Docker blocks by default, which `--security-opt seccomp=unconfined` allows. That option loosens the container's own filter on system calls, and nothing else. It doesn't give the container more access to the computer.

You can leave the option out. Autonomous sessions then run unsandboxed and say so, and the container is the only thing keeping agents in.

## Update it

- **Sesh updates itself** in the container, like on any other machine: it installs new versions when no agent is working and no terminal is open (**Update Automatically** in the machine's **Details…**). Or click **Update** when it says **Needs Update**.
- **Pull the image for newer agents,** and to keep the update when the container is created again:

  ```sh
  docker pull ghcr.io/sesh-codes/sesh:claude
  docker rm -f sesh
  ```

  Then run the same `docker run` command as before. With Docker Compose: `docker compose pull && docker compose up -d`.

Your sessions, sign-ins and projects are in the volume, so they carry over. Sessions that were working pick up where they left off.

## Where things are kept

Everything is in the container's home folder, `/home/sesh`, which is the volume:

- `~/code`: projects
- `~/.local/share/sesh`: sessions, paired devices, settings and agents added with **Get**
- `~/.claude`, `~/.codex`, `~/.gemini`, `~/.cursor`, `~/.local/share/opencode`: the agents' sign-ins and settings
- `~/.config/gh`, `~/.gitconfig`: GitHub sign-in and git settings

To back it up, back up the volume. To start over, remove the container and then the volume: `docker volume rm sesh-home`.

> **A folder instead of a volume.** To keep it in a folder on the computer, use `-v /path/to/folder:/home/sesh` instead. The container runs as user ID 1000, so the folder must be writable by that user: `sudo chown 1000:1000 /path/to/folder` on Linux.

## More than one container

Each container is its own machine in Sesh: give each one its own name, volume and UDP port, for example `--name sesh-codex --hostname sesh-codex -v sesh-codex-home:/home/sesh -p 4778:4777/udp`.

## If something's wrong

**It says Offline.** Check that the container is running with `docker ps`, and read Sesh's log with `docker logs sesh`. The container needs to reach the internet.

**Autonomous sessions say they aren't sandboxed.** Start the container with `--security-opt seccomp=unconfined`. If they still say so on a Linux computer, also add `--security-opt apparmor=unconfined`.

**Cloning a private repository fails.** Clones use the container's git sign-in, not your Mac's. Run `docker exec -it sesh gh auth login`.

**A sign-in, project or session is gone after updating.** The container was started without `-v sesh-home:/home/sesh`, or with a different volume name. Start it with the same volume each time.

**Permission denied on a folder mounted from the computer.** The container runs as user ID 1000. Make the folder writable by it, as in [Where things are kept](#where-things-are-kept).
