Why run an AI agent in a VM

If you've used an AI coding agent, whether Open Interpreter, a LangChain agent, Claude Code or anything else that runs generated code, you've accepted that it can do anything your user account can. That's not hypothetical: Docker's engineering blog has documented real AI coding agent incidents. Indirect prompt injection makes it worse than "the agent might make a mistake", because an instruction hidden in a file the agent reads can run commands with all your permissions.

The fix is a VM, which gives you a hardware-enforced boundary. What's gone wrong in practice covers why permission prompts and command allowlists haven't been enough.

Keep the model out of the VM

Apple's Virtualization framework doesn't give Linux guests the Mac's GPU. Run the model inside the VM and it's CPU-only, which for a 7B+ model is a slowdown you feel. So the goal is narrower than "put the agent in a VM": keep the model on the Mac's GPU, move only the agent's code execution into the VM, and connect them fast enough that the split costs nothing noticeable. Velo Workspaces' AI Bridge is a channel built for exactly that.

September 2026: that limit is current, not permanent. The Cua project has published a software workaround that reports benchmarked speedups for one inference engine inside a Linux guest. It isn't official GPU passthrough, but it's worth watching.

┌───────────────────────────────────────────────────────────────────┐
│                            macOS HOST                             │
│                                                                   │
│      Ollama / MLX Engine   ───►  Storage: ~/.ollama/models        │
│      (Native Metal GPU)          (single 10GB–50GB copy)          │
│              ▲                                                    │
│              │  Velo Workspaces AI Bridge                         │
│              │  proxies to localhost:<port>                       │
│              ▼                                                    │
│      ┌─────────────────────────────────────────────────────┐      │
│      │                     LINUX VM                        │      │
│      │  socat 127.0.0.1:<port>  ⇄  vsock CID 2             │      │
│      │  Env: OPENAI_API_BASE=http://127.0.0.1:<port>/v1    │      │
│      │  Dev apps / Docker containers / VS Code / Python    │      │
│      └─────────────────────────────────────────────────────┘      │
└───────────────────────────────────────────────────────────────────┘
The model stays on the Mac's GPU; only the agent's code execution moves into the VM. AI Bridge is the vsock channel between them.

Setup

Since Ollama 0.19 (March 2026), Ollama runs on MLX underneath on Macs with 32 GB or more. This guide installs MLX directly either way; AI Bridge's Host Provider setting works the same for both.

1. Install an MLX server on the Mac

MLX needs Python 3.10 or newer; the Python that comes with Apple's developer tools is too old, so install one with Homebrew.

Install Homebrew if you don't have it:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install Python 3.12 and create a virtual environment:

brew install python@3.12
python3.12 -m venv ~/.venv

Install MLX-LM and start the server inside the virtual environment:

source ~/.venv/bin/activate
pip install --upgrade pip
pip install mlx-lm
mlx_lm.server --model mlx-community/Qwen2.5-Coder-7B-Instruct-4bit --port 8080

2. Create the workspace

In Velo Workspaces, choose AI Workspace in the sidebar and click + in the upper right. Choose Cloud image and Ubuntu 26.04 LTS: it's Ubuntu Server, light on memory, and ready about a minute after it downloads, with no installer to go through.

On the Configure step, choose the AI Sandbox profile, open Show Advanced Settings, set CPU, memory and disk, and make sure AI Bridge is on with Host Provider set to MLX. Enter a username and password, then click Create Workspace.

Velo Workspaces New Workspace wizard, Configure step: AI Sandbox profile selected (8 CPU · 16 GB), CPU Cores/Memory/Storage set to 4/4/64, and AI Bridge enabled with Host Provider set to MLX.Click to enlarge
An AI Sandbox configuration for an MLX-backed workspace: AI Bridge on, Host Provider set to MLX.

3. Connect AI Bridge inside the VM

When the workspace is ready, open its Access tab and click Open Terminal (Pro), or copy the ssh command into Terminal (it uses your own SSH key, so add your public key when you create the workspace). Then install socat and add a service that forwards 127.0.0.1:8080 into AI Bridge. (The workspace's AI Bridge tab shows these commands with a Copy button.)

sudo apt update
sudo apt install -y socat
sudo tee /etc/systemd/system/velo-ai-bridge.service >/dev/null <<'EOF'
[Unit]
Description=Velo Workspaces AI Bridge (127.0.0.1:8080 to the host over the high speed channel)
After=network.target

[Service]
ExecStart=/usr/bin/socat TCP-LISTEN:8080,fork,reuseaddr,bind=127.0.0.1 VSOCK-CONNECT:2:8080
Restart=always
RestartSec=2

[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable velo-ai-bridge
sudo systemctl restart velo-ai-bridge

4. Install OpenCode in the VM

Install curl, git and build-essential (which OpenCode uses when building and managing repositories), then install OpenCode with its official install script:

sudo apt install -y curl git build-essential
curl -fsSL https://opencode.ai/install | bash

Reload your shell so it finds the new opencode command:

source ~/.bashrc

Create the configuration file:

mkdir -p ~/.config/opencode
nano ~/.config/opencode/opencode.json

Paste in this configuration:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "mlx-local": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "MLX Local Server",
      "options": {
        "baseURL": "http://127.0.0.1:8080/v1"
      },
      "models": {
        "mlx-community/Qwen2.5-Coder-7B-Instruct-4bit": {
          "name": "Qwen 2.5 Coder 7B (4-bit)"
        }
      }
    }
  },
  "model": "mlx-local/mlx-community/Qwen2.5-Coder-7B-Instruct-4bit"
}

Start OpenCode:

opencode

In OpenCode's terminal interface, open the connection wizard:

/connect

Select MLX Local Server, and when it asks for an API key, type mlx.

That's a fully local AI agent: the model and the agent both on your own hardware, private, with no API bill.

OpenCode terminal UI inside the VM, connected to the MLX Local Server provider, generating and running a Python script for the 1000th Fibonacci number using Qwen 2.5 Coder 7B (4-bit).Click to enlarge
OpenCode in the VM, talking to Qwen 2.5 Coder 7B over AI Bridge.

What does this cost in inference speed? See the MLX benchmark, or read the architecture behind AI Bridge. For the full version with Ollama and three more agents, see the complete guide. AI Bridge supports four backends, and the AI researchers post lists them, with a gotcha when switching between them. Or just download Velo Workspaces and try it yourself.