Skip to content
hettigerPublic

About

Let coding agents work autonomously in sandboxes on macOS. Each crannog is its own VM via Apple Containers, reachable only through causeways you control: git remotes for code, an allowlisting proxy for the network, optional mounts. Claude Code, Codex, OpenCode and Pi built in.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

171 Commits

Folders and files

Repository files navigation

crannog

crannog lets coding agents work autonomously in sandboxes.

Like its namesake, an island dwelling in a lake, a crannog is isolated from its surroundings. Each crannog runs in its own lightweight VM. The only ways in and out are causeways you control:

  • git: code enters through plain git remotes, and the agent's commits come back the same way. Nothing else of your repository or your machine is inside.
  • a network proxy: the crannog reaches only the domains you allow, plus services on your Mac that listen on all interfaces (0.0.0.0).
  • mounts, optionally, for what you decide to share.
  • SSH, optionally, for editors and other tools on your Mac.

Claude Code, Codex, OpenCode and Pi come preinstalled, share their logins across crannogs and can call each other. They run without permission prompts: the crannog is the security boundary.

Status: proof of concept. Expect rough edges and breaking changes.

Requirements

  • macOS 26 or later on Apple Silicon
  • Apple Containers (container CLI, container system start has run once)
  • git

Installation

Requires Go.

curl -fsSL https://raw.githubusercontent.com/hettiger/crannog/main/install.sh | bash

This installs crannog and the git remote helper git-remote-crannog with go install and links both into /usr/local/bin, so that git clients that do not load your shell's PATH, such as GUI apps, find the helper, and installs the man page (man crannog). If /usr/local/bin or the man directory is not writable for you, it asks to use sudo, or prints the commands. It also adds one item, "crannog keychain", to your login keychain: the password of crannog's own keychain for secrets. Run it again to update. From a checkout, make install does the same with the checkout's code, and make build builds both binaries into dist/.

For a shorter name, add alias cg=crannog to your ~/.zshrc; completion works for the alias too.

Before the first session: Claude Code's token

Without this step, every request of Claude Code fails as unauthorized. The default setup keeps Claude Code's subscription token out of the crannogs: Claude Code only has a placeholder, and the proxy adds the token to its requests. Create the token once and set it for all crannogs:

crannog checkout -- zsh   # a shell in a crannog: run claude setup-token, copy the token
crannog secret set claude-subscription-token   # on your Mac: paste the token

To log in with /login as usual instead, remove CLAUDE_CODE_OAUTH_TOKEN from .crannog/config.yml: crannog preset publish default writes the default setup to the repository first. For all repositories without .crannog/, put the edited preset in ~/.crannog/presets/default/. While the placeholder is set, /login does not help.

Usage

In any git repository:

crannog checkout                      # session in the crannog of the checked-out branch
crannog checkout feature/x -- zsh     # a shell in the crannog of feature/x
crannog checkout -- claude -p "Fix the failing test"
crannog checkout -d                   # keep the crannog running in the background
crannog stop                          # end its sessions and stop it

The first checkout builds the crannog, which takes a few minutes. When the last session ends, the crannog stops; the next session starts it again. With -d, crannog starts a detached session, which only waits or runs the command after --, and returns: the crannog keeps running in the background.

While a session runs, crannog merge fast-forwards your branch to the agent's, and crannog push also pushes it, where git push would. The crannog is a git remote of your repository then, too:

git fetch crannog-<slug>              # the agent's branches
git push crannog-<slug> main          # your new commits into the crannog
Command Does
crannog checkout [branch] [-- command...] Opens a session in the crannog of a branch
crannog checkout -d [branch] [-- command...] Starts a detached session and returns
crannog apply [branch] Applies changes to .crannog/ without opening a session
crannog stop [branch] Ends the sessions of the crannog and stops it
crannog destroy [branch] Destroys the crannog after a confirmation
crannog list Lists the repository's crannogs
crannog merge [branch] Fast-forwards the branch to the agent's branch in its running crannog
crannog push [branch] Does merge, then pushes the branch where git push would
crannog ssh [branch] [-- command...] Opens a shell over SSH in a running crannog
crannog ssh [branch] -H / -p / -Hp Prints the crannog's SSH host, the path in it, or <host>:<path> for scp; -c copies it
crannog open [branch] Opens a running crannog in the browser (-i for http, -p for a port); -c copies the URL
crannog open [branch] --zed Opens a running crannog in Zed; -c copies the URL
crannog open [branch] --mysql / --postgres Opens a running crannog's database server in a database client (-p for a port); -c copies the URL
crannog preset publish [name] Writes a preset to .crannog/
crannog preset list Lists all presets
crannog secret set <name> Sets a secret the proxy adds to requests: globally, -r for the repository, -c for a crannog
crannog secret forget <name> Forgets a secret
crannog secret list [name] Lists the secrets that apply here, or where one is set; never values

crannog completion <shell> prints a completion script for bash, zsh, fish or PowerShell, which completes branches, preset names and secret names; see crannog completion --help. crannog man prints a man page of all commands, which install.sh installs (man crannog). Both are left out of the command list.

Tools on your Mac

Editors with remote development (Zed, PhpStorm), terminal multiplexers and ssh reach a running crannog over SSH, without a network port. Enable it once by adding this line at the top of ~/.ssh/config:

Include ~/.crannog/ssh/config

crannog never edits ~/.ssh itself. Then open a shell with crannog ssh, open the repository in Zed with crannog open --zed, or connect tools to the host crannog ssh --host prints:

crannog checkout -d
crannog ssh
crannog open --zed
scp notes.txt "$(crannog ssh -Hp)/"

crannog open opens a server in the crannog in your browser, at the crannog's address.

See SSH causeway for Zed, JetBrains IDEs, Rex and caveats, and open.

Configuration

A repository configures its crannogs in .crannog/: config.yml (session command, resources, proxy image, environment, mounts), iron-proxy.yaml (the proxy's allowlist and settings) and container/ (the image's build context). Without .crannog/, crannog uses the bundled preset default; crannog preset publish default writes it to the repository as a starting point.

crannog only uses a setup you approved: when .crannog/ changes, including changes an agent committed, it shows the diff and asks before using it.

Documentation

docs/ holds the glossary, the architecture decisions, the features and the use cases.

License

MIT

About

Let coding agents work autonomously in sandboxes on macOS. Each crannog is its own VM via Apple Containers, reachable only through causeways you control: git remotes for code, an allowlisting proxy for the network, optional mounts. Claude Code, Codex, OpenCode and Pi built in.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages