Sulat.com / Writing on AIFriday, December 4, 2026
Enter →
Agent Engineering/3 December 2026

Connect Colab to Codex, Claude Code and opencode

Google gives coding agents three routes into Colab: a CLI, a local MCP server and a remote endpoint. I ran the CLI with all three agents on a T4, then served a model from Colab behind each of them.

3D Google Colab logo beside a terminal prompt, connecting coding agents to Colab GPUs
Illustration: Sulat, featuring the Google Colab logo

At a glance

  • Google has three official routes for agents into Colab: the colab CLI, a local colab-mcp server and a remote MCP endpoint at colaboratory.googleapis.com.
  • The CLI is the simplest: opencode, Codex and Claude Code each read its bundled skill and ran Python on a Colab T4 through a plain shell command.
  • Codex needs its sandbox config changed before the CLI works, because workspace-write keeps ~/.config read-only and blocks the network.
  • A vLLM server on the T4 answered chat completions, Responses and Messages calls through one SSH tunnel, so all three agents ran against a Colab-hosted model.
  • Colab's FAQ requires a positive balance for SSH, and bans serving or proxying from a runtime, so the tunnel is a one-person setup.

Google gives coding agents three official routes into Colab: the colab command-line tool, a local MCP server and a remote MCP endpoint. I installed the CLI, signed it in, started a T4 runtime and pointed opencode, Codex and Claude Code at it. Then I served a model from that T4 and pointed all three agents at it through an SSH tunnel.

The short answer is to use the CLI. Every agent already has a shell, and colab exec is all it needs. The two MCP routes each need something extra, and below is what each one needs and where I hit snags. The same tunnel trick is how Alexey Fateev’s launcher runs a 96 GB model on a Colab G4.

Which route to use

RouteWhat the agent getsWhat you needOutput
Colab CLIA shell tool: new, exec, ssh, upload, download, stopLinux or macOS and a Google sign-inAnything the code prints, plus files via download
Local colab-mcpTools for working in a notebook you have openA Colab tab in a browser on the same machine, and a client that handles tool-list updatesNotebook edits in the browser
Remote MCP endpoint10 tools, from create_runtime to execute_codeA token with the colaboratory scope and a Google Cloud quota projectText only, no plots
Source: the google-colab-cli and colab-mcp READMEs and Google’s Colab MCP reference.
Diagram of three routes from a coding agent to Colab: CLI, local MCP server and remote MCP endpoint
Three official ways for an agent to reach Colab.

Route 1: the Colab CLI

The CLI is Google’s own, published as google-colab-cli, and it runs on Linux and macOS only. I used version 0.8.0.

Code
uv tool install google-colab-cli
colab new -s t4 --gpu T4
echo 'print("hello from Colab")' | colab exec -s t4
colab usage
colab stop -s t4

The first command that needs Google prints a consent URL. You open it, approve, and paste the code back into the terminal. After that colab new brought up a T4.

Terminal showing colab new starting a T4 GPU session, colab status and the usage rate
colab new starts a T4 runtime.

colab skill prints a bundled skill called colab-operator, which tells an agent how to drive the CLI. That’s the hook for agents. I asked each one to read it first and then use the runtime that already existed, and I allowed Claude Code only the CLI with --allowedTools "Bash(colab:*)". This is the exact prompt:

Code
Read the Colab CLI skill with `colab skill`, then use the `colab` CLI on the existing session named t4 (do not create or stop sessions). Run Python on that session that prints the GPU name and total memory, and whether PyTorch can see CUDA. Report the output.

All three agents read the skill, ran Python on the T4 and reported Tesla T4, 15,360 MiB of memory (14.56 GiB in PyTorch) and CUDA visible. opencode used Claude Haiku 5.5 from the OpenCode catalogue.

opencode terminal run calling colab exec to check the GPU on a Colab T4
opencode drives Colab through the colab CLI with no extra setup.
Codex terminal run using the colab CLI to report the GPU on a Colab T4 runtime
Codex needs ~/.config writable before the colab CLI works inside its sandbox.
Claude Code terminal run calling the colab CLI to check the GPU on a Colab T4
Claude Code runs the same check through its Bash tool.

Snags

  • Codex. Its workspace-write sandbox keeps ~/.config read-only and blocks the network, so the CLI can’t save its token cache or reach Google. Add the config folder as a writable root and turn network access on (config below).
  • opencode. opencode run waits on stdin in a script. Add </dev/null and it returns.
  • Sign-in default. The README and --help default --auth to oauth2, while the bundled skill shows adc. If a command asks for credentials you haven’t set up, pass --auth oauth2.
  • Orphan runtimes. A colab new that times out can leave a runtime running. Run colab usage afterwards; with nothing running the rate reads 0.00/hr.
  • One SSH session. colab ssh allows one concurrent connection per runtime, so keep it for the tunnel below and use colab exec for everything else.

The Codex config that fixed the sandbox, in config.toml:

Code
[sandbox_workspace_write]
writable_roots = ["/home/you/.config/colab-cli"]
network_access = true

Route 2: the local MCP server

colab-mcp is a bridge between a local agent and a Colab notebook open in your browser. It runs over stdio, so the client has to be on the same device as the browser, and it has to handle tools/list_changed notifications. The README names Gemini CLI, Claude Code and Windsurf. This is the config:

Code
{
  "mcpServers": {
    "colab-mcp": {
      "command": "uvx",
      "args": ["git+https://github.com/googlecolab/colab-mcp"],
      "timeout": 30000
    }
  }
}

I started it and listed its tools. Before a browser tab connects it exposes one, open_colab_browser_connection, and the notebook tools appear after the tab connects. I didn’t connect a tab, so I haven’t run the notebook-editing tools. This route suits working inside a notebook with an agent beside you. It doesn’t suit a headless agent on a server.

Route 3: the remote MCP endpoint

Google also runs an MCP server at https://colaboratory.googleapis.com/mcp. Its tools cover runtimes and sessions: create_runtime, list_runtime_specs, create_session, execute_code, get_runtime and the matching list, get and delete calls. Listing the tools needs no sign-in, which is the curl call on Google’s reference page. Calling them does. You need a token with the colaboratory scope and a Google Cloud quota project, and without the project the call came back with a 403 that says so.

Two limits from Google’s reference matter for agents. execute_code is cut off after 600 seconds with DEADLINE_EXCEEDED while the code keeps running, and you reattach by repeating the call with the same executionId. Output is text only, so plots and images don’t come back. Claude Code can attach a bearer token to an MCP server through a headersHelper script. I stopped at the 403, so I haven’t run execute_code on this route.

Run the model on Colab instead

The routes above put the compute on Colab and the agent on your machine. You can also put the model on Colab. vLLM serves one model over three API shapes, and each agent speaks a different one:

  • opencode uses OpenAI chat completions, at /v1/chat/completions.
  • Codex uses the Responses API, at /v1/responses.
  • Claude Code uses the Anthropic Messages API, at /v1/messages.
Diagram mapping vLLM chat completions to opencode, responses to Codex and messages to Claude Code
vLLM speaks the API each agent expects.

On the T4 I installed vLLM and served Qwen3-4B-Instruct-2507. The 15 GB card can’t hold much cache, so I capped the context at 24,576 tokens:

Code
vllm serve Qwen/Qwen3-4B-Instruct-2507 --port 8000 --served-model-name coder --dtype half --max-model-len 24576 --gpu-memory-utilization 0.88 --enable-auto-tool-choice --tool-call-parser hermes

Then I forwarded the port to my machine through the CLI’s SSH proxy mode:

Code
ssh -N -o ProxyCommand="colab ssh --proxy-mode -s t4" -L 127.0.0.1:18000:127.0.0.1:8000 root@colab-t4
Diagram of a laptop agent reaching a vLLM server on a Colab GPU through an SSH tunnel
The model runs on Colab and the agent stays on your machine.

A single curl to each endpoint came back with “Hello there!” in the shape that agent expects.

Terminal showing a Colab-hosted vLLM server answering chat completions, responses and messages endpoints
One Colab-hosted vLLM server answered all three API shapes.

Pointing each agent at the tunnel takes a few lines. opencode, in opencode.json:

Code
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "colab": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Colab T4",
      "options": {
        "baseURL": "http://127.0.0.1:18000/v1",
        "apiKey": "sk-local"
      },
      "models": {
        "coder": {
          "name": "Qwen3 4B on Colab",
          "limit": {
            "context": 24576,
            "output": 2048
          }
        }
      }
    }
  },
  "model": "colab/coder"
}

Codex, in config.toml, with COLAB_LOCAL_KEY set to any string:

Code
model = "coder"
model_provider = "colab"

[model_providers.colab]
name = "Colab T4"
base_url = "http://127.0.0.1:18000/v1"
wire_api = "responses"
env_key = "COLAB_LOCAL_KEY"

Claude Code reads the Anthropic base URL from the environment, so it points at http://127.0.0.1:18000 without the /v1 suffix.

For the test I gave each agent one small job:

Code
Create fizzbuzz.py that prints FizzBuzz for 1 to 15, run it with python3, and show me the output.

opencode, Codex and Claude Code each wrote the file, ran it and printed the right sequence with the model on the T4. Getting there took three adjustments:

  • Tool calls. A 3B coder model printed its tool calls as plain text, so no agent could act on them. Qwen3-4B-Instruct-2507 with the hermes parser returned real tool calls.
  • Claude Code’s prompt. Its default system prompt and tool list overflowed the 24,576-token window, and vLLM refused the request. --bare, a trimmed tool set and a lower CLAUDE_CODE_MAX_OUTPUT_TOKENS got it under the limit.
  • Codex edits. The served model doesn’t support Codex’s apply_patch tool, so Codex wrote the file with a shell command instead.
Diagram comparing a 3B coder printing tool calls as text with Qwen3 4B returning real tool calls
A small model only works if it returns real tool calls.

A 4B model on a T4 is good enough to prove the wiring and not much more. The point is that the wiring is identical for a bigger card, which is what the G4 launcher does with a far larger model.

What it costs and what Colab allows

A T4 ran at about 1.2 compute units an hour in my sessions, and colab usage shows the live rate and your balance. A G4 runs at about 10, the rate users have logged, and the earlier piece on the G4 launcher works through what each Google plan’s units buy.

Colab’s FAQ draws three lines that matter here:

  • SSH, remote control and web UIs as a secondary feature need a positive paid balance. At a zero balance Colab applies free-tier rules, which don’t allow them.
  • Offering a web service from a runtime and using it as a remote proxy are banned on every runtime.
  • The terms bar giving third parties access to your runtime.

The tunnel above binds to 127.0.0.1, so it’s built for one person using their own model. Sharing it with a team breaks those rules. The CLI route over colab exec is the one that fits the plainest reading of them.

What I didn’t run

  • Fateev’s G4 launcher and the 96 GB model. It needs a G4 and a plan that can start one.
  • The notebook-editing tools in colab-mcp, which need a connected browser tab.
  • execute_code on the remote endpoint, which needs a quota project.

Sources

Disclosure: I’m an OpenAI, Firecrawl and Devin ambassador.