Skip to content

Instantly share code, notes, and snippets.

@emiloberg
Last active April 10, 2026 17:09
Show Gist options
  • Select an option

  • Save emiloberg/de1b3f2b92257b8afc366575772681a7 to your computer and use it in GitHub Desktop.

Select an option

Save emiloberg/de1b3f2b92257b8afc366575772681a7 to your computer and use it in GitHub Desktop.
Claude sandbox with Apple Container

Running Claude in a lightweigh VM on Mac.

container is Apple's tool that you can use to create and run Linux containers as lightweight virtual machines on your Mac. Requires Apple Silicon and macOS 26+.

This guides you through running Claude in a container.

There is a single catalog that can be written by both host and guest. No other access from guest to host is allowed.

Step 1 — Install Apple Container

Download the latest .pkg-packet from github.com/apple/container/releases. Pick the signed package.

Double click and follow the installation guide.

Start the service

container system start

Accept the default kernel.

Verify that everything is running

container system status

Step 2 — Create catalogs

mkdir -p ~/code/shared # Catalog shared guest <-> host
mkdir -p ~/claude-sandbox
touch ~/claude-sandbox/Dockerfile
cd ~/claude-sandbox

Step 3 - Create Dockerfile

This Dockerfile installs asdf, node and Claude Code. You add whatever you want to add.

FROM ubuntu:24.04

RUN apt-get update && apt-get install -y --no-install-recommends \
    curl git ca-certificates sudo \
    dirmngr gpg gawk \
    && rm -rf /var/lib/apt/lists/*

RUN useradd -m -s /bin/bash claude && \
    echo "claude ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

USER claude
WORKDIR /home/claude

# Installer asdf for tool version handling (Go-binary, v0.16+)
ARG ASDF_VERSION=v0.16.7
RUN curl -fsSL \
    "https://github.com/asdf-vm/asdf/releases/download/${ASDF_VERSION}/asdf-${ASDF_VERSION}-linux-arm64.tar.gz" \
    | tar -xz -C /tmp && \
    mkdir -p ~/.local/bin && \
    mv /tmp/asdf ~/.local/bin/asdf

# Add to PATH to get it to work in interactive shells
RUN echo 'export PATH="$HOME/.local/bin:$HOME/.asdf/shims:$PATH"' >> ~/.bashrc && \
    echo 'export PATH="$HOME/.local/bin:$HOME/.asdf/shims:$PATH"' >> ~/.profile

ENV PATH="/home/claude/.local/bin:/home/claude/.asdf/shims:$PATH"

# Install node via asdf
RUN asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git && \
    asdf install nodejs latest && \
    asdf set -u nodejs latest

# Install Claude
RUN curl -fsSL https://claude.ai/install.sh | bash

WORKDIR /workspace

Step 4 - Build image

container build -t claude-sandbox .

check that image exists

container image ls

Step 5 - Create container

container run -it \
  --name claude-sandbox \
  --cpus 4 \
  --memory 4G \
  -v "$HOME/code/shared:/workspace" \
  -u claude \
  -w /workspace \
  claude-sandbox \
  bash

Step 6 - Run Claude

Inside container

claude

or if you're feeling it

claude --dangerously-skip-permissions

Step 7 - Create startup script

To make it easier to start, you can use this startup script.

Create e.g this file ~/claude-sandbox/start.sh

#!/bin/bash
set -e

# Start Apple Container-service
if ! container system status &>/dev/null; then
  container system start
fi

# Start container if stopped
if container ls -a | grep -q "claude-sandbox"; then
  container start claude-sandbox 2>/dev/null || true
  container exec -it -u claude claude-sandbox bash -c \
    'cd /workspace && claude --dangerously-skip-permissions'
else
  # Create container if it doesn't exists
  container run -it \
    --name claude-sandbox \
    --cpus 4 \
    --memory 4G \
    -v "$HOME/code/shared:/workspace" \
    -u claude \
    -w /workspace \
    claude-sandbox \
    bash -c 'claude --dangerously-skip-permissions'
fi

Fix permissions

chmod +x ~/claude-sandbox/start.sh

Run as

~/claude-sandbox/start.sh

Seamlessly open Claude

This in your .zshrc/.bashrc/.whateverrc gives you the command claudex which you can run from a folder open Claude, for that folder, in a sandbox.

alias sandbox='container exec -it -u claude claude-sandbox bash'

claudex() {
  local shared_base="$HOME/code/shared"
  local current="$(pwd)"

  if [[ "$current" != "$shared_base"* ]]; then
    echo "❌ Not in a folder shared with sandbox. Navigate somewhere under $shared_base and run it again"
    return 1
  fi

  local relative="${current#$shared_base}"
  local guest_dir="/workspace${relative}"

  container exec -it -u claude claude-sandbox bash -c "cd '$guest_dir' && claude --dangerously-skip-permissions"
}

Good to know

List containers:

container ls

If it shows up, you can stop buildkit, if you want to. It will autostart when building an image.

container builder stop

List containers, including stoppped

container ls -a

Connect to guest

container exec -it -u claude claude-sandbox bash

or add it as an alias in your ~/.zshrc, ~/.bashrc, etc

alias sandbox='container exec -it -u claude claude-sandbox bash'

or quick command into Claude

container exec -it -u claude claude-sandbox bash -c 'claude --dangerously-skip-permissions'

or add that as an alias

alias claudes='container exec -it -u claude claude-sandbox bash -c "claude --dangerously-skip-permissions"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment