> ## Documentation Index
> Fetch the complete documentation index at: https://docs.microsandbox.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Code

> Run Anthropic's Claude Code against a project on your host

This guide installs a pinned Claude Code release inside a Node.js microVM and opens it in a project mounted from your host. Claude Code can edit the checkout directly, while its installation, authentication, settings, and sessions stay on the sandbox's root disk.

## Run Claude Code

**1. Start Claude Code**

Local-only (Writable host-directory mounts are local-only. On microsandbox cloud, use the isolated-copy alternative and omit replace-on-create.)

Replace `./my-project` with the project directory you want Claude Code to work on:

```sh macOS & Linux theme={null}
msb run -t --name claude-code-demo --replace \
  --cpus 2 --memory 4G --root-disk 4G \
  --mount-dir ./my-project:/workspace:rw \
  --workdir /workspace \
  node:24-bookworm-slim -- sh -lc '
    apt-get update &&
    apt-get install -y --no-install-recommends ca-certificates git &&
    npm install -g @anthropic-ai/claude-code@2.1.235 &&
    exec claude
  '
```

```powershell Windows theme={null}
msb run -t --name claude-code-demo --replace `
  --cpus 2 --memory 4G --root-disk 4G `
  --mount-dir ./my-project:/workspace:rw `
  --workdir /workspace `
  node:24-bookworm-slim -- sh -lc '
    apt-get update &&
    apt-get install -y --no-install-recommends ca-certificates git &&
    npm install -g @anthropic-ai/claude-code@2.1.235 &&
    exec claude
  '
```

Choose a terminal theme, then follow the sign-in prompts. If Claude Code cannot open a browser from the microVM, copy the displayed login URL and open it in a browser on your host.

Anthropic recommends its standalone installer for normal host installations. This guide uses the pinned npm package for a reproducible sandbox setup; the package installs the same platform-native Claude Code binary.

> [!TIP]
>
> For an isolated workspace, or when using microsandbox cloud, replace `--mount-dir ./my-project:/workspace:rw` with `--copy-dir ./my-project:/workspace`.

**2. Start another session**

After leaving Claude Code, return to the same sandbox and workspace with:

```sh Shell theme={null}
msb exec -t claude-code-demo -- claude
```

The sandbox root disk retains Claude Code's authentication, configuration, and conversation state between sessions.

**3. Verify the installation**

Exit the TUI and run:

```sh Shell theme={null}
msb exec claude-code-demo -- claude --version
```

The pinned example prints `2.1.235 (Claude Code)`.

**4. Review or export changes**

With the default writable mount, changes are already in the host checkout. Review them inside the sandbox:

```sh Shell theme={null}
msb exec claude-code-demo -- sh -lc 'cd /workspace && git status --short && git diff --stat && git diff'
```

If you chose the isolated `--copy-dir` alternative, create a patch inside the sandbox:

```sh Shell theme={null}
msb exec claude-code-demo -- sh -lc 'cd /workspace && git add -N . && git diff --binary > /tmp/claude-code.patch'
```

Copy the patch to the host:

```sh Shell theme={null}
msb cp claude-code-demo:/tmp/claude-code.patch ./claude-code.patch
```

Check that it applies cleanly before applying it:

```sh Shell theme={null}
git apply --check ./claude-code.patch
```

**5. Clean up**

Remove the sandbox:

```sh Shell theme={null}
msb rm -f claude-code-demo
```

Removing the sandbox also removes its Claude Code credentials, settings, and sessions. Changes made through the default workspace mount remain in the host checkout.

## Reference

* [Claude Code setup](https://code.claude.com/docs/en/setup)
* [Claude Code authentication](https://code.claude.com/docs/en/authentication)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.