# Devcontainer for using O(x)Caml and Claude in your projects

*2026-01-08 — note*


I got a few questions about the dev setup I used for my [AoAH](https://anil.recoil.org/notes/aoah-2025) sprint last month.
I've cleaned this up and published
**[claude-ocaml-devcontainer](https://github.com/avsm/claude-ocaml-devcontainer)**,
a [Devcontainer](https://devcontainers.io) of everything you need to do OCaml
or OxCaml development in Claude Code in a sandboxed Docker container. This means you
can (reasonably safely) run it in unattended mode with permissions bypass enabled.


## Using the OCaml/Claude devcontainers

A devcontainer can either be used in an editor that supports it like VSCode, or directly from the CLI (which is what I do for Claude Code). Adding it to your project is as simple as:

```
$ mkdir .devcontainer
$ cd .devcontainer
$ curl -OL https://raw.githubusercontent.com/avsm/claude-ocaml-devcontainer/refs/heads/main/.devcontainer/devcontainer.json
```

Edit the JSON file to add any other post-installation or extensions that you might need for that project. It's intended to be customisable.

To spin the devcontainer up, I use the npx CLI:

```
$ npx @devcontainers/cli up   --workspace-folder .
$ npx @devcontainers/cli exec --workspace-folder . bash -l
```

This will mount your current project into `/workspace` in the dev container. The set of network domains that can be accessed are limited to a [select few](https://github.com/avsm/claude-ocaml-devcontainer/blob/main/.devcontainer/init-firewall.sh#L68-L83), but I'll parameterise this into the project metadata in the future.

When you're in the workspace container, you have two preinstalled OCaml switches:

```bash
$ opam switch
#  switch    compiler                 description
   5.2.0+ox  ocaml-variants.5.2.0+ox  5.2.0+ox
→  default   ocaml.5.4.0              default
```

And `claude` maps its config from your home directory, so you can start up sessions once you've authenticated as normal, and everything runs in the container reasonably sandboxed.

## Customising the devcontainers

Since compiling up O\[x\]Caml can take a while, it's a prebuilt image, but you can also clone the [repository](https://github.com/avsm/claude-ocaml-devcontainer) and customise the Dockerfile in `.devcontainer` to your heart's content.
The default disk space in a GitHub Action wasn't sufficient, but it turns out that the default `ubuntu-latest` has a ton of pre-installed packages [that you can just delete to double your disk space](https://carlosbecker.com/posts/github-actions-disk-space/).

One pretty cool thing about the action is that it doesn't use qemu to build the
multiarch images. Instead, the
[multibuild.yml](https://github.com/avsm/claude-ocaml-devcontainer/blob/main/.github/workflows/multi-build.yaml)
dispatches separate builds to the native arm64 and amd64 hosts, and then
combines them together. This is faster and more reliable than the conventional
path of going through CPU emulation for the non-native host.

I also modify my own devcontainer to mount some limited SSH keys and a
`.gitconfig` so I can commit from within the container, which allows for more
unattended feedback loops.

Synopsis: A prebuilt Docker devcontainer for sandboxed OCaml and OxCaml development with Claude Code, including multiarch builds and network isolation.
Words: 407

Discussion:
- Bluesky: <https://bsky.app/profile/anil.recoil.org/post/3mbvto4po322y>

## Related

- [Weeknotes for week 3](https://jon.recoil.org/blog/2026/01/weeknotes-2026-03.html) (feed, 2026-01-19)
- [2025 Advent of Agentic Humps: Building a useful O(x)Caml library every day](https://anil.recoil.org/notes/aoah-2025) (note, 2025-12-26)
- [OxCaml Labs](https://anil.recoil.org/projects/oxcaml) (project, 2025-01-01)

---
Canonical: https://anil.recoil.org/notes/ocaml-claude-dev
Type: note
Tags: ocaml, oxcaml, docker
