Skip to content

Add claude sandbox#337

Merged
gilesknap merged 2 commits intoDiamondLightSource:claude-sandboxfrom
gilesknap:add-claude-sandbox
Apr 29, 2026
Merged

Add claude sandbox#337
gilesknap merged 2 commits intoDiamondLightSource:claude-sandboxfrom
gilesknap:add-claude-sandbox

Conversation

@gilesknap
Copy link
Copy Markdown
Contributor

Three new copier questions gate a sandboxed Claude Code setup: add_claude (top-level — env var blockers, ~/.claude bind mount, Claude Code CLI install, postCreate/postStart hooks, node, justfile), install_gh and install_glab (each gated on add_claude).
Breaks the template/.devcontainer symlink so devcontainer.json can be Jinja-conditional. The meta repo's own .devcontainer/devcontainer.json and Dockerfile become the add_claude=no baseline; a new test_meta_matches_no_claude_template drift test enforces it.
Adds remote.autoForwardPorts: false and explicit forwardPorts: [8000] so VS Code stops stealing sphinx-autobuild's port on restart (separate commit).

gilesknap and others added 2 commits April 29, 2026 12:37
Three new copier questions gate a sandboxed Claude Code setup:
add_claude (top-level — env var blockers, ~/.claude bind mount,
Claude Code CLI install, postCreate/postStart hooks, node, justfile);
install_gh and install_glab (each gated on add_claude — adds the CLI
install plus per-repo PAT volume mount and matching just recipe).

Breaks the template/.devcontainer symlink so devcontainer.json can be
Jinja-conditional. The meta repo's own .devcontainer/devcontainer.json
and Dockerfile become the add_claude=no baseline. A new
test_meta_matches_no_claude_template drift test renders the template
with all Claude opts off and byte-diffs the result against the meta
repo to catch divergence.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
VS Code's auto-detection races with sphinx-autobuild on container
restart and steals the port, breaking the live-reload docs preview.
Disable it and forward 8000 explicitly so the docs URL is stable.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gilesknap gilesknap merged commit d645eb3 into DiamondLightSource:claude-sandbox Apr 29, 2026
3 of 4 checks passed
Comment on lines +51 to +54
// Explicitly forward sphinx-autobuild port (auto-detection disabled above)
"forwardPorts": [
8000
],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this? When you click on the link it autoforwards the port anyway...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got pulled in from my project that was having issues with sphinx-autobuild - I'm not sure why it fighting it - but we should not have this by default - agreed.

// Mount the parent as /workspaces so we can pip install peers as editable
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",{% if add_claude %}
"postCreateCommand": ".devcontainer/postCreate.sh",
"postStartCommand": ".devcontainer/postStart.sh"{% else %}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we always put a postCreate in and jinja template just the claude bits?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think yes - its tidier than long bash entries embedded in the devcontainer.json

pre-commit install --install-hooks

# Initialise git submodules if any are declared
[ -f .gitmodules ] && git submodule update --init || true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line is useful in the non-claude case too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - I thought I had dropped that. It is useful for first opening a devcontainer that needs submodules to build, but ...... if you rebuild your container while you are in progress with submodule changes they disapear. I think that cost outweighs the benefit.

So I vote to take this back out.

Comment thread template/Dockerfile.jinja
Comment on lines +15 to +22
# GitHub CLI — used by Claude to authenticate to github.com via PAT
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | \
dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && \
chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg && \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
| tee /etc/apt/sources.list.d/github-cli.list > /dev/null && \
apt-get update && apt-get install -y --no-install-recommends gh && \
apt-get dist-clean{% endif %}{% if install_glab %}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.46.0-4 is in apt for 26.04, is that new enough?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should think yes - so lets do as you suggest below and put these in the base container from 26.04 onwards and claude enabled PCT will use that.

Comment thread template/Dockerfile.jinja
ARG GLAB_VERSION=1.92.1
RUN curl -fsSL "https://gitlab.com/gitlab-org/cli/-/releases/v${GLAB_VERSION}/downloads/glab_${GLAB_VERSION}_linux_amd64.tar.gz" \
| tar -xz -C /tmp bin/glab && \
install -m 0755 /tmp/bin/glab /usr/local/bin/glab && \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.53.0-1build1 is in apt for 26.04, is that new enough?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above.

Comment thread template/Dockerfile.jinja

# Node is required by Claude Code's hook runtime
RUN apt-get update -y && apt-get install -y --no-install-recommends \
nodejs \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this plus gh plus glab be in the ubuntu devcontainer base?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

Comment thread copier.yml
Comment on lines +124 to +138
install_gh:
type: bool
when: "{{ add_claude }}"
help: |
Install the GitHub CLI (gh) so Claude can push/pull via PAT auth?
Only useful inside the Claude sandbox — ordinary users typically
rely on SSH keys or VS Code git credentials.

install_glab:
type: bool
when: "{{ add_claude }}"
help: |
Install the GitLab CLI (glab) for projects that talk to a GitLab
instance (e.g. gitlab.diamond.ac.uk submodules)?
Only useful inside the Claude sandbox.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I reckon we should probably just include these in the ubuntu devcontainer unconditionally

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my first instinct and then I thought people would push back on it especially since glab would be a less common requirement. But if you like always including then I do to.

@gilesknap
Copy link
Copy Markdown
Contributor Author

@coretl sorry about the WIP PR - in retrospect that was a bad idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants