Google Colab has always lived in the browser. You open a notebook, pick a runtime, and run your code in a tab. That works well for experiments, but it is a poor fit for automation, scheduled jobs, and AI coding agents that live in the terminal. Google's answer is the Colab CLI, an official command-line interface that provisions Colab's cloud GPUs and TPUs, runs your local Python scripts on them, and tears the machines down again — all without opening a notebook. This guide walks you through installing it, authenticating, provisioning your first GPU runtime, and running real AI workloads from your terminal.
What Is Google Colab CLI?
The Colab CLI is Google's official command-line tool for Google Colab, released on 5 June 2026 and published as open source under the Apache 2.0 licence in the googlecolab GitHub organisation. It turns Colab from a browser-only notebook into a programmable remote runtime that you drive from your own shell. From one terminal you can spin up CPU, GPU, or TPU runtimes in seconds, execute local code on them, manage remote files, and orchestrate automated cloud pipelines.
The tool is deliberately small and predictable. Sessions, execution, files, and automation are the four areas it covers. You provision a session with colab new, run code with colab exec, move files with colab upload and colab download, and stop everything with colab stop. When you only need a result, colab run collapses the whole cycle — provision, execute, destroy — into a single command.
It is worth being clear about what the CLI is not. It does not replace the notebook for interactive exploration, plotting, and step-by-step debugging. It is a headless companion for the jobs where a notebook tab gets in the way: training runs, batch inference, benchmarks, and scripts triggered by another tool. Google also ships a sibling project, the Colab MCP Server, for people who want interactive, agent-assisted coding inside a notebook instead of a terminal workflow.
Why Run Colab from the Terminal?
The most obvious benefit is that your workflow stops depending on a browser tab. A terminal session can be scripted, logged, retried, and scheduled. A training script that runs for two hours no longer needs a notebook kept awake in the background, and its output can be piped straight into your normal logging and monitoring.
The second benefit is for AI coding agents. Tools such as Claude Code, Codex, and Google's Antigravity all work through the terminal, and Google designed the CLI with them in mind. The package even ships a prepackaged skill file, COLAB_SKILL.md, that tells any agent with shell access how to drive the tool. An agent can provision an A100, run a benchmark, pull the results back, and shut the machine down, all without a human clicking through a notebook interface.
The third benefit is reproducibility. A colab run command with its flags is a complete, replayable record of a job: which accelerator it used, which script it ran, and which arguments it passed. That is far easier to share with a colleague, or with your future self, than a notebook with a runtime you configured by hand six weeks ago.
What You Need Before You Start
Four things are required, and it is worth checking them off before you install anything. First, a computer running Linux or macOS. The CLI currently supports Linux and macOS only; Windows is not supported at this time, although running it inside WSL2 is the usual workaround for Windows users. Second, Python 3.13 or newer, since the pip installation path requires it. Third, a Google account with access to Colab, because the CLI provisions the same rented runtimes as the notebook and accelerator access is subscription- and quota-gated. Fourth, uv, the fast Python package manager, which Google recommends as the installer — although plain pip works too.
On the Colab side, your plan decides which accelerators you can actually use. A free account can reach the entry-level GPUs, while the larger accelerators and the high-memory machine shapes need a paid Colab Pro or Pro+ entitlement. If a command fails with an HTTP 400 when you request a GPU, that usually means your plan has no entitlement for it — fall back to a smaller accelerator or a CPU runtime rather than retrying the same command.
Step 1 — Install the Colab CLI
Installation is a single command. Google recommends uv, which installs the tool in its own isolated environment:
uv tool install google-colab-cli
If you prefer pip, that works as well, provided your Python is 3.13 or newer:
pip install google-colab-cli
An earlier route installed directly from the GitHub repository with uv tool install git+https://github.com/googlecolab/google-colab-cli, and that still works, but the PyPI package is now the standard path. Once installed, confirm the tool is on your path and check which version you have:
colab --help
colab update
The colab update command checks for a newer release and, with the --install flag, upgrades the CLI in place. It is worth running whenever you return to the tool after a break, because the project is still young and its command surface is evolving.
Step 2 — Authenticate Your Google Account
The CLI needs to prove who you are before it can rent you a machine. It supports two authentication modes, selected with the global --auth flag. Application Default Credentials, or ADC, is the default and the mode Google prefers for agents and automation. OAuth2 is the alternative, using a browser flow on first use, with the resulting token stored at ~/.config/colab-cli/token.json.
Whichever mode you use, verify it before you spend money on a GPU. The colab whoami command confirms you are authenticated and shows that the right scopes are in place. ADC needs four specific OAuth scopes, including the colaboratory scope that keeps the runtime alive, so a successful whoami is the cheapest way to catch a permissions problem early:
colab whoami
If authentication fails, the usual cause is a missing scope or a stale token. Re-authenticating with the other mode often resolves it, and the official README in the GitHub repository is the authoritative reference for the current flags if a command changes.
Step 3 — Provision Your First Cloud Runtime
Provisioning a runtime is one command. Running colab new with no flags allocates a CPU session, which is the default and the cheapest way to confirm everything works:
colab new
Add a GPU with the --gpu flag. The supported values are T4, L4, G4, H100, and A100. A T4 is the sensible first choice for a smoke test, while an A100 is the workhorse for large-model training:
colab new --gpu T4
colab new --gpu A100
TPUs use the --tpu flag, with v5e1 and v6e1 available:
colab new --tpu v6e1
Give the session a name with -s so you can manage it later, and add --high-mem when you need a high-RAM machine shape. Note that the high-memory flag requires a Colab Pro or Pro+ entitlement for supported accelerators, and that L4 and TPU runtimes ignore it because they only offer one shape:
colab new -s trainer --gpu A100 --high-mem
Once a session exists, colab sessions lists your active VMs and colab status shows the hardware and metadata of the current one. If you ever want the browser view of the same session, colab url --open hands you a link that attaches to it. Spell GPU names exactly as documented: an unrecognised --gpu value can silently map to an A100 in the client, which is an expensive surprise.
Step 4 — Run a Python Script on a Cloud GPU
With a session running, execution is straightforward. The colab exec command runs Python from standard input, from a local .py file, or from a notebook. The important detail is that colab exec -f script.py reads the file locally and sends the source to the remote kernel — there is no separate upload step for execution:
colab exec -f train.py
For interactive work, colab repl opens an interactive Python REPL on the remote runtime, and colab console gives you a raw TTY shell. If you prefer your own editor, colab ssh opens a shell over WebSocket, and it can also act as an OpenSSH ProxyCommand bridge for IDE remote development, so VS Code or a similar editor can work directly against the cloud machine.
A practical first test is a short script that prints the accelerator it finds, which confirms the GPU is really attached before you commit to a long job. Run it, watch the streamed output, and only then launch the real workload. Streaming output and exit-code propagation mean a failed remote script fails your local command too, which is exactly what you want in a scripted pipeline.
Step 5 — Install Packages and Manage Files
A fresh runtime has little installed beyond the basics, so the next step is usually dependencies. The colab install command installs packages on the VM using uv, falling back to pip when needed. You can pass package names directly or point at a requirements file:
colab install -r requirements.txt
colab install torch transformers datasets
File management uses a small set of commands that mirror the obvious verbs: colab upload and colab download move files between your machine and the runtime, colab ls lists remote files, colab rm deletes them, and colab edit opens one for editing. The typical pattern for a training job is to upload a dataset or a checkpoint directory, install the requirements, run the script, and download the resulting weights before stopping the machine. Google Drive can also be mounted from the runtime if your data already lives there, and GCP credentials can be attached for jobs that need to reach other Google Cloud services.
One habit saves repeated pain: keep your requirements file next to your script and install from it every time, rather than installing packages interactively and forgetting what the job needed. A runtime is disposable by design, and anything you installed by hand disappears with it.
Step 6 — Run One-Shot Jobs with colab run
For jobs you run once and do not need to babysit, colab run is the most useful command in the whole tool. It provisions a fresh VM, runs your script, streams the output, propagates the exit code, and then tears the VM down — provision, execute, destroy in a single invocation:
colab run --gpu A100 train.py --epochs 3
Arguments after the script name are forwarded to the script, so --epochs 3 above reaches train.py as normal. Add --keep if you want the VM to survive after the script finishes, for example when you expect to inspect the results interactively before shutting it down. Without that flag, the machine is released as soon as the job ends, which is the safest default: it makes it impossible to leave an expensive GPU idling overnight because you forgot about it.
This one-shot pattern is also the right shape for scheduled work. A cron job or a CI step can call colab run with a fixed accelerator and script, and the cost of the job is bounded by the runtime of that single execution. Use it for one-shot training and inference jobs, not as a persistent development box — if you find yourself keeping the same VM alive for days, the notebook or a proper cloud VM is a better home for that work.
Step 7 — Stop the Runtime and Clean Up
When the work is done, stop the runtime. colab stop releases the VM and ends billing for it, and colab restart-kernel clears the kernel state without releasing the machine when you only need a clean slate. Make stopping a habit, and verify it:
colab stop
colab sessions
The second command should show no active sessions. If it still lists one, stop it by name. Download any artefacts you need — model weights, logs, exported notebooks — before you stop, because a released runtime takes its filesystem with it. The CLI can export replayable .ipynb logs of a session, which is a useful record of what actually ran, especially for jobs an agent launched on your behalf.
Which GPU or TPU Should You Pick?
The accelerator menu is short, and each option has a natural job. The T4 is the budget choice, suited to fine-tuning small models, inference smoke tests, and learning the tool. The L4 is a step up for larger inference and medium training jobs. The G4 covers newer mid-range workloads. The A100 remains the standard for large-model training, and the H100 is the top end for the heaviest jobs. For TPU-native JAX and Flax work, v5e1 is the established slice and v6e1 the newer one.
Start smaller than you think you need and scale up only when the job proves it. A T4 that finishes a smoke test in minutes tells you more, for less money, than an A100 booked on a guess. Remember that accelerator availability depends on your active Colab plan, and that a 400 error on colab new --gpu X is the service telling you the plan does not cover that accelerator — step down rather than retrying.
Using Colab CLI with AI Coding Agents
The CLI's most interesting audience may not be humans at all. Because it is a terminal tool with a small, predictable command surface, any coding agent with shell access can drive it: Claude Code, Codex, and Google's Antigravity are the examples Google names. The bundled COLAB_SKILL.md file gives such agents the usage pattern in a form they can follow without guessing.
The practical shape is simple. You ask the agent to run a benchmark or train a model, and it provisions the accelerator, installs the dependencies, runs the script, downloads the artefacts, and stops the runtime. The agent's own terminal session is the control plane, and the Colab VM is just the compute it borrows for the job. Keep an eye on this pattern if you build agent workflows, because it removes the most awkward step in giving an agent a GPU: the provisioning code you would otherwise have to write yourself. Set sensible guardrails, though — an agent with access to colab new --gpu H100 and no spending limit is a bill waiting to happen, so agree the accelerator and the stop behaviour before the agent starts.
What It Costs
There is no CLI-specific cost. The tool itself is free and open source, and you pay only for the accelerator time, billed exactly the way Colab has always billed it, through Colab's normal compute-unit pricing. A CPU session is the cheapest way to learn the commands, a T4 is the cheapest GPU, and the bill scales with the size of the accelerator and the length of the job.
The cost discipline that matters most is the one the tool already encourages: release runtimes you are not using. One-shot colab run jobs release themselves, named sessions do not, so a named session you forget is the main way a small experiment turns into an unwelcome charge. Check colab sessions at the end of the day until the habit sticks, and confirm the pricing on the official Colab pricing page before committing to a large job, since pricing and features change frequently.
Troubleshooting Common Errors
Most failures fall into a handful of buckets. An HTTP 400 when provisioning usually means your Colab plan has no entitlement for the requested accelerator; step down to a T4 or a CPU runtime. A command that complains about Python usually means the local Python is older than 3.13; installing through uv avoids that class of problem entirely. Authentication failures most often trace back to a missing OAuth scope, and re-authenticating — or switching between ADC and OAuth2 — resolves them.
If a session seems stuck, colab status tells you what the runtime actually looks like, and colab restart-kernel clears state without losing the machine. If the CLI itself behaves oddly, colab update is worth running before anything else, because the project is young and a fix may already be released. And if a GPU name is rejected, double-check the spelling: the recognised values are T4, L4, G4, H100, and A100 for GPUs, and v5e1 and v6e1 for TPUs.
Colab CLI vs the Notebook: When to Use Each
The notebook still wins for interactive exploration, visualisation, and teaching. Nothing in the CLI replaces a cell you can re-run while you watch a chart update. The CLI wins for everything repeatable: training scripts, scheduled jobs, benchmarks, and agent-driven work. A good rule is to develop in the notebook and deploy through the CLI — prototype interactively, then hand the finished script to colab run for the real execution.
The CLI also appeared in the 9 November 2026 roundup of new AI tools, a sign that terminal-first AI workflows are moving from a niche for infrastructure engineers into the mainstream of everyday AI development. As agents take on more of the coding, the ability to hand them a GPU from a single command is becoming a basic skill rather than a party trick. Learning it now, while the tool is young and the command surface is small, is the cheapest time to do it.
What to Try Next
Start with a CPU session and a script that prints a greeting, then move to a T4 and a small inference job, and only then try an A100 training run. Read the official README in the googlecolab/google-colab-cli repository before you rely on any command in production, since this is a young project and its flags can change. If you already run models locally, compare the two approaches: our guide to running AI models locally with Ollama and Nvidia GPU covers the local side, while our Gemini 3 guide shows the browser-based alternative. And if you work with AI coding agents, our comparison of Cursor vs Claude Code vs Devin Desktop will help you pick the agent that should be driving the CLI for you.
#GoogleColab #ColabCLI #AITools #CloudGPU #Python #MachineLearning #AITutorial
Comments (0)