Claude Code with OpenRouter in a Sandbox
Introduction
Claude Code with OpenRouter in a Sandbox

Claude Code with OpenRouter in a Sandbox
Introduction
As developers, we love experimenting with the latest AI developer tools. But let’s be honest: installing every new CLI tool directly onto your host machine can quickly turn into a configuration nightmare. Conflicts between dependencies, messy global environments, and security concerns are enough to make anyone hesitate.
If you want to test Claude Code Anthropic’s powerful command-line agent without cluttering your main operating system, there is a better way.
By isolating Claude Code inside a persistent Docker container running a full Ubuntu desktop environment and routing its power through OpenRouter, you get a completely walled-off, highly customizable, and secure developer sandbox.
Here is precisely how to set it up.
Why Sandbox Claude Code?
Sandboxing your AI development tools offers three massive advantages:
- Isolation: Your host OS (whether Windows, macOS, or Linux) remains completely untouched.
- Persistence: By using Docker volumes, all of your files, projects, and configurations stay intact even if you stop or restart the container.
- Flexibility via OpenRouter: Instead of juggling multiple individual LLM accounts and API keys, OpenRouter gives you a unified interface to access Claude models seamlessly with a single token.
The Prerequisites
Before diving into the terminal, please ensure you have two things ready:
- Docker Desktop: Installed and running on your host machine.
- An OpenRouter Account: Sign up, log in, and generate a new API key (it will look like
sk-or-...).
Step 1: Spin Up the Ubuntu Desktop Sandbox
Instead of a bare-bones terminal container, we are using a Kasm Web Ubuntu Jammy desktop image. This gives us a full visual desktop environment accessible directly from any web browser.
Open your host terminal (like PowerShell or bash) and execute the Docker run command to start your sandbox:
Powershell
## Run Docker
>> docker run -d --name kasm-desktop --shm-size=1024m -p 6901:6901 -e VNC_PW=Random@32 -e KASM_USER=root --user root -v C:\Users\yogen\kasm-files:/home/kasm-user/persistent kasmweb/ubuntu-jammy-desktop:1.18.0
## See all docker containers
>> docker ps
Note: You can adjust the configuration to attach a local storage volume to ensure your project files remain persistent on your host machine.
Once the container is running, open your favorite browser and navigate to: [https://localhost:6901](https://localhost:6901)
Log in using the credentials configured in your setup, and you’ll be greeted by a shiny new Ubuntu desktop interface right inside your browser tab.
Step 2: Install the Claude Code CLI
Inside your browser-based Ubuntu desktop, open up a terminal application. Because this is a fresh environment, you have full root access to experiment.
To download and install the official Claude Code command-line tool, simply run the following installation script:
Bash
## Check Linux (Ubuntu) Version (Optional Only for Sanity)
>> cat /etc/os-release
## Install Claude Code
>> curl -fSSL https://claude.ai/install.sh | bash
The script will automatically configure the necessary paths and binary configurations for you.
Step 3: Wire OpenRouter to Claude's Code
By default, Claude Code expects a standard Anthropic API key. To trick it into using OpenRouter’s unified interface instead, we need to create a project-level local settings file.
- Create your main project folder and navigate into it:
## Sample Folder
>> mkdir FirstProject && cd FirstProject
## Create a hidden configuration directory named `.claude`:
>> mkdir .claude && cd .claude
## Create settings.local.json
>> touch settings.local.json
- Create a file named
settings.local.jsonand paste the following structure, making sure to substitute your actual OpenRouter key:
JSON
{
"env": {
"ANTHROPIC_BASE_URL": "https://openrouter.ai/api",
"ANTHROPIC_AUTH_TOKEN": "sk-or-your-actual-open-router-key-here",
"ANTHROPIC_API_KEY": ""
}
}
By pointing the ANTHROPIC_BASE_URL directly to OpenRouter and feeding your token into the auth parameter, Claude Code will now communicate effortlessly through the OpenRouter proxy network.
Step 4: Launch and Test inside VS Code
The beauty of the Kasm Ubuntu image is that it comes pre-installed with Visual Studio Code.
- Launch VS Code inside your container sandbox and open your
FirstProjectfolder. - Head to the Extensions marketplace, search for Claude Code for VS Code, and install it.
- Open the integrated Claude Code panel. Thanks to your
settings.local.jsonenvironment variables, the tool will initialize without demanding a standard Anthropic login.
To verify that everything works, type a test instruction into the agent chat terminal, such as:
“List files in directory”
You will see Claude Code analyze your sandbox file structure, execute the bash query locally within the container bounds, and report back the results in real-time.
Wrap Up
You now have a fully operational, completely isolated playground for Claude Code. You can let the AI agent read files, write scripts, and execute terminal commands with zero anxiety about what it might do to your primary computer. If anything ever breaks or goes sideways, you can simply tear down the Docker container and spin up a pristine new sandbox in seconds.
Github Link :: https://github.com/scholarly360/Claude-Code-with-OpenRouter-in-a-Sandbox
[embed]
메타데이터
- post_id
- 3fc4a984e4cc
- slug
- claude-code-with-openrouter-in-a-sandbox-3fc4a984e4cc
- url
- https://medium.com/@scholarly360/claude-code-with-openrouter-in-a-sandbox-3fc4a984e4cc
- canonical_url
- https://medium.com/@scholarly360/claude-code-with-openrouter-in-a-sandbox-3fc4a984e4cc
- author_url
- https://medium.com/@scholarly360
- status
- ok
- fetched_at
- 2026-07-11 03:31:55