← back to guides

Sandbox: WSL2 on Windows 11

codehamr runs shell commands written by an LLM. WSL2 keeps those commands inside a Linux VM instead of your Windows install.

Two pieces:

  • Ollama Desktop on Windows, using your GPU.
  • codehamr inside WSL2, a real Linux sandbox.

They talk to each other over plain localhost, thanks to WSL2 mirrored networking (Windows 11 22H2+). No Docker Desktop, no GPU passthrough.

For the plain non-sandboxed path see the Windows quickstart.

1. Install Ollama Desktop on Windows

Follow steps 1 and 2 of the Windows quickstart: install Ollama, lift the context length, pull a model — then come back here.

Then let Ollama accept connections from WSL2 — by default it only listens on localhost. In PowerShell, set a Windows environment variable, then quit and restart Ollama from the system tray:

PowerShell

setx OLLAMA_HOST "0.0.0.0"

This exposes Ollama on your local network — fine on a trusted machine.

2. Install WSL2

In PowerShell as administrator:

wsl --install

Reboot when Windows asks. Ubuntu launches and prompts for a Linux username and password — pick anything simple.

Confirm:

wsl --status

You want Default Version: 2.

One more thing: by default WSL2 mounts your Windows drives at /mnt/c. Seal the sandbox by turning that off inside Ubuntu (you won't see C:\ from Linux anymore — your projects live in the Linux filesystem):

Ubuntu terminal

printf '\n[automount]\nenabled=false\n' | sudo tee -a /etc/wsl.conf

It takes effect with the wsl --shutdown you run in the next step.

3. Enable mirrored networking

This makes localhost inside WSL2 reach your Windows host directly. Create the file %UserProfile%\.wslconfig (in your Windows user folder) with:

%UserProfile%\.wslconfig

[wsl2]
networkingMode=mirrored

Then restart WSL from PowerShell so it takes effect:

wsl --shutdown

4. Install codehamr inside WSL2

Inside the Ubuntu terminal:

curl -fsSL https://codehamr.com/install.sh | bash
codehamr --version

5. Point codehamr at the host's Ollama

In your project:

.codehamr/config.yaml

active: local

models:
    local:
        llm: your-model
        url: http://localhost:11434
        key: ""
        context_size: 256000

context_size here must be the Context length you set in Ollama — larger silently truncates server-side.

With mirrored networking, localhost from WSL2 is your Windows host — exactly as if codehamr ran on Windows directly.

6. Run

codehamr

GPU on Windows, agent in Linux, your Windows files untouched.

If something doesn't work

From the WSL terminal:

curl -sS http://localhost:11434/v1/models
  • JSON back → all good, recheck url: in your config.
  • Connection refused → Ollama Desktop isn't running, or you skipped OLLAMA_HOST=0.0.0.0 (set it, then restart Ollama).
  • Still refused after that → mirrored networking isn't active. Check .wslconfig and that you ran wsl --shutdown. On Windows 10 (no mirrored mode), use the host IP instead: run ip route show | grep -i default | awk '{print $3}' in WSL and set url: http://<that IP>:11434.

VS Code

Install the WSL extension on Windows, then Ctrl+Shift+P → WSL: Open Folder in WSL. Run codehamr in the integrated terminal.