本周,谷歌 AI 团队发布了 Colab CLI。该工具可将本地终端连接到远程 Colab 运行时环境,让开发者和 AI 智能体能够在云端 GPU 和 TPU 上运行代码,且全程无需离开终端。该 CLI 基于 Apache 2.0 许可证开源。
什么是 Google Colab CLI
Colab CLI 是 Google Colab 的命令行界面。你可以通过终端创建会话、运行代码和管理文件。
任何拥有终端访问权限的智能体都可以调用该工具,包括 Claude Code、Codex 以及谷歌的 Antigravity。谷歌附带提供了一个名为 COLAB_SKILL.md 的预封装技能文件,为智能体提供如何使用该 CLI 的内置上下文。
安装只需在 GitHub 仓库中执行一条 uv tool install 命令。
uv tool install git+https://github.com/googlecolab/google-colab-cli 一个最简会话示例如下:
colab new # provision a CPU session
echo "print('hello')" | colab exec # run code
colab stop # release the VM
命令如何工作
CLI 将命令分为会话、执行、文件和自动化几类。colab new 用于配置会话,默认使用 CPU。添加 --gpu T4、--gpu L4、--gpu A100 或 --gpu H100 可使用 GPU。TPU 选项为 v5e1 和 v6e1。
colab exec 可从标准输入、.py 文件或笔记本运行 Python 代码。该命令在本地读取文件并传输其内容,因此本地编辑后无需单独的上传步骤。colab stop 用于终止会话并释放虚拟机。
其他命令涵盖文件和身份验证。colab upload 和 colab download 用于在本地和远程之间移动文件。colab drivemount 用于挂载 Google Drive,默认路径为 /content/drive。colab auth 用于对虚拟机进行 Google Cloud 服务身份验证。
colab exec 与工件恢复:核心循环
核心循环非常简短:配置运行时、运行脚本、然后拉取结果。colab download 用于检索模型、数据集和其他文件。colab log 将会话历史导出为 .ipynb、.md、.txt 或 .jsonl 格式。
这样,一次远程运行就变成了磁盘上一个可重放的笔记本。colab repl 和 colab console 提供对虚拟机的交互式访问。colab install 使用 uv 添加包,并在必要时回退到 pip。会话元数据存储在 ~/.config/colab-cli/sessions.json 中。
示例:微调 Gemma 3 1B
Google 官方发布展示了一个智能体驱动的微调任务。该任务使用 QLoRA 对 google/gemma-3-1b-it 进行微调。它在 Text-to-SQL 数据集上进行训练,以提升 SQL 生成能力。Antigravity 智能体通过五个命令运行完整的流水线。
colab new --gpu T4
colab install transformers datasets peft trl bitsandbytes accelerate
colab exec -f finetune_run.py
colab log --output gemma_finetune_log.ipynb
colab stop 随后,该智能体下载适配器模型、适配器配置、分词器配置和分词器。你可以在本地加载并提供微调后的模型服务。用户无需手动输入任何云端资源调配命令。
使用场景
- 将笔记本电脑上的训练任务卸载到远程 GPU 或 TPU,无需离开终端。
- 让 Claude Code、Codex 或 Antigravity 等智能体运行端到端的机器学习流水线。
- 使用 QLoRA 远程微调 Gemma 3 1B 等小型模型。
- 编写笔记本执行脚本,并导出可复现的 .ipynb 日志文件。
- 通过 colab repl 或 colab console 在虚拟机上交互式调试。
Colab CLI 与基于浏览器的 Colab
CLI 并不会取代笔记本用户界面。它的目标是脚本化、自动化以及智能体驱动的工作。以下是两种工作流在常见任务上的对比。
| 维度 | 基于浏览器的 Colab | Colab CLI |
|---|---|---|
| 界面 | 网页笔记本 UI | 本地终端 |
| 加速器选择 | 浏览器中的运行时菜单 | colab new 命令的 --gpu / --tpu 标志 |
| 智能体使用 | 手动,UI 驱动 | 通过命令使用任何终端智能体 |
| 运行本地脚本 | 粘贴或上传到代码单元格中 | colab exec -f script.py |
| 工件获取 | 手动下载或通过云端硬盘 | colab download, colab log |
| 包安装 | 在单元格内使用 !pip | colab install(使用 uv,然后是 pip) |
| 会话控制 | 浏览器管理的运行时 | colab new, colab stop, colab status |
| 智能体技能文件 | 无 | 内置的 COLAB_SKILL.md |
优势与注意事项
优势:
- 终端原生工作流适用于脚本、CI 和智能体循环。
- 单条命令即可配置 T4、L4、A100 或 H100 GPU。
- exec 命令会发送本地文件内容,因此无需上传步骤。
- 日志可导出为可复现的笔记本格式,确保可复现性。
- 在 Apache 2.0 许可下开源,并附带一个内置的智能体技能文件。
- 可与多种智能体配合使用,而非单一供应商的工具。
注意事项:
- 访问需要身份验证;默认策略是 oauth2。
- repl 和 console 在交互式运行时需要 TTY。
- 在脚本中使用这两个命令时,需要通过管道传入标准输入。
- 计算仍在 Colab 的后端及其运行时模型上运行。
关键要点
- Google 的 Colab CLI 可让您从本地终端在远程 Colab GPU 和 TPU 上运行代码。
- 一条命令即可配置加速器:`colab new --gpu` 支持从 T4 到 A100 和 H100,外加 TPU。
- `colab exec` 可将本地的 `.py` 和 `.ipynb` 文件直接发送到运行时,无需上传步骤。
- 任何终端智能体——Claude Code、Codex、Antigravity——都可以通过捆绑的 `COLAB_SKILL.md` 来驱动它。
- 它在 Apache 2.0 许可下开源,并且 `colab log` 可导出可回放的笔记本日志。
Marktechpost 可视化讲解
Google Colab CLI — 终端指南
概述
从终端运行 Colab GPU 和 TPU
Google Colab CLI 将您的本地终端连接到远程 Colab 运行时。开发者和 AI 智能体无需离开 Shell 即可在云端加速器上运行代码。
2026 年 6 月 5 日发布 • 在 Apache 2.0 许可下开源
第一步
它是什么
- 一个用于 Google Colab 的命令行界面。
- 它将您的本地终端连接到远程 Colab 运行时。
- 您可以从终端创建会话、运行代码和管理文件。
- 任何基于终端的 AI 智能体也可以调用它。
第二步
安装与快速开始
通过一条命令安装,然后运行第一个会话。
uv tool install git+https://github.com/googlecolab/google-colab-cli
colab new # provision a CPU session
echo "print('hello')" | colab exec # run code
colab stop # release the VM 第三步
配置 GPU 和 TPU
创建会话时请求一个加速器。默认使用 CPU。
colab new --gpu T4
colab new --gpu A100
colab new --tpu v6e1 加速器的可用性取决于您当前的 Colab 套餐。
第四步
远程运行本地脚本
`exec` 命令在本地读取您的文件并发送其内容。无需单独的上传步骤。
colab exec -f train.py `exec` 可从标准输入、`.py` 文件或笔记本运行 Python。
第五步
获取模型和日志
运行后将结果拉取回您的机器。
colab download -s NAME checkpoints/model.bin ./model.bin
colab log -o report.ipynb 日志可导出为 `.ipynb`、`.md`、`.txt` 或 `.jsonl` 格式。
第六步
示例:微调 Gemma 3 1B
Google 的博客展示了一个智能体在 Text-to-SQL 数据集上运行 QLoRA 流程。
colab new --gpu T4
colab install transformers datasets peft trl bitsandbytes accelerate
colab exec -f finetune_run.py
colab log --output gemma_finetune_log.ipynb
colab stop 第七步
专为 AI 智能体打造
- 任何具有终端访问权限的智能体都可以调用 CLI。
- 它与 Claude Code、Codex 和 Antigravity 兼容。
- 捆绑的 `COLAB_SKILL.md` 为智能体提供了内置上下文。
- 结果:可脚本化、智能体就绪的 Colab 算力。
This week, Google AI team released the Colab CLI. The tool connects your local terminal to remote Colab runtimes. It lets developers and AI agents run code on cloud GPUs and TPUs. You stay in your terminal the entire time. The CLI is open source under the Apache 2.0 license.
What is Google Colab CLI
The Colab CLI is a command-line interface for Google Colab. You can create sessions, run code, and manage files from the terminal.
Any agent with terminal access can call the tool. That includes Claude Code, Codex, and Google’s Antigravity. Google ships a prepackaged skill file named COLAB_SKILL.md. It gives agents built-in context on how to use the CLI.
Installation uses a single uv tool install command from the GitHub repository.
uv tool install git+https://github.com/googlecolab/google-colab-cli A minimal session looks like this:
colab new # provision a CPU session
echo "print('hello')" | colab exec # run code
colab stop # release the VM
How the Commands Work
The CLI groups commands into sessions, execution, files, and automation. colab new provisions a session, with CPU as the default. Add --gpu T4, --gpu L4, --gpu A100, or --gpu H100 for a GPU. TPU options are v5e1 and v6e1.
colab exec runs Python from stdin, a .py file, or a notebook. The exec reads files locally and ships their contents. Local edits therefore need no separate upload step. colab stop terminates the session and releases the VM.
Other commands cover files and authentication. colab upload and colab download move files between local and remote. colab drivemount mounts Google Drive, defaulting to /content/drive. colab auth authenticates the VM for Google Cloud services.
colab exec and Artifact Recovery: The Core Loop
The core loop is short. You provision a runtime, run a script, then pull results back. colab download retrieves models, datasets, and other files. colab log exports session history as .ipynb, .md, .txt, or .jsonl.
So a remote run becomes a replayable notebook on your disk. colab repl and colab console give interactive access to the VM. colab install adds packages with uv, falling back to pip. Session metadata is stored at ~/.config/colab-cli/sessions.json.
Example: Fine-Tuning Gemma 3 1B
Google’s official release demonstrates an agent-driven fine-tuning job. The task fine-tunes google/gemma-3-1b-it using QLoRA. It trains on a Text-to-SQL dataset to improve SQL generation. The Antigravity agent runs the full pipeline with five commands.
colab new --gpu T4
colab install transformers datasets peft trl bitsandbytes accelerate
colab exec -f finetune_run.py
colab log --output gemma_finetune_log.ipynb
colab stop The agent then downloads the adapter model, adapter config, tokenizer config, and tokenizer. You can load and serve the fine-tuned model locally. No manual cloud provisioning command was typed by the user.
Use Cases
- Offload laptop-bound training to a remote GPU or TPU without leaving the terminal.
- Let agents like Claude Code, Codex, or Antigravity run end-to-end ML pipelines.
- Fine-tune small models, such as Gemma 3 1B, with QLoRA remotely.
- Script notebook execution and export replayable
.ipynblogs for reproducibility. - Debug interactively on the VM through
colab replorcolab console.
Colab CLI vs Browser-Based Colab
The CLI does not replace the notebook UI. It targets scripted, automated, and agent-driven work instead. Here is how the two workflows compare across common tasks.
| Dimension | Browser-Based Colab | Colab CLI |
|---|---|---|
| Interface | Web notebook UI | Local terminal |
| Accelerator selection | Runtime menu in the browser | --gpu / --tpu flags on colab new |
| Agent use | Manual, UI-driven | Any terminal agent via commands |
| Run local scripts | Paste or upload into cells | colab exec -f script.py |
| Artifact retrieval | Manual download or Drive | colab download, colab log |
| Package install | !pip inside a cell | colab install (uv, then pip) |
| Session control | Browser-managed runtime | colab new, colab stop, colab status |
| Agent skill file | None | Bundled COLAB_SKILL.md |
Strengths and Considerations
Strengths:
- Terminal-native workflow fits scripts, CI, and agent loops.
- One command provisions T4, L4, A100, or H100 GPUs.
execships local file contents, so no upload step is needed.- Logs export to replayable notebook formats for reproducibility.
- Open source under Apache 2.0, with a bundled agent skill file.
- Works with multiple agents, not a single vendor’s tool.
Considerations:
- Access requires authentication; the default strategy is
oauth2. replandconsoleneed a TTY when run interactively.- Pipe stdin to use those two commands inside scripts.
- Compute still runs on Colab’s backend and its runtime model.
Key Takeaways
- Google’s Colab CLI runs code on remote Colab GPUs and TPUs from your local terminal.
- One command provisions accelerators:
colab new --gpu T4throughA100andH100, plus TPUs. colab execships local.pyand.ipynbfiles to the runtime without an upload step.- Any terminal agent — Claude Code, Codex, Antigravity — can drive it via a bundled
COLAB_SKILL.md. - It is open source under Apache 2.0, and
colab logexports replayable notebook logs.
Marktechpost Visual Explainer
Google Colab CLI — Terminal Guide
Overview
Run Colab GPUs and TPUs from your terminal
The Google Colab CLI connects your local terminal to remote Colab runtimes. Developers and AI agents run code on cloud accelerators without leaving the shell.
Announced June 5, 2026 • Open source under Apache 2.0
Step 1
What it is
- A command-line interface for Google Colab.
- It connects your local terminal to remote Colab runtimes.
- You create sessions, run code, and manage files from the terminal.
- Any terminal-based AI agent can call it too.
Step 2
Install and quick start
Install with a single command, then run a first session.
uv tool install git+https://github.com/googlecolab/google-colab-cli
colab new # provision a CPU session
echo "print('hello')" | colab exec # run code
colab stop # release the VM Step 3
Provision GPUs and TPUs
Request an accelerator when you create the session. CPU is the default.
colab new --gpu T4
colab new --gpu A100
colab new --tpu v6e1 Accelerator availability depends on your active Colab plan.
Step 4
Run local scripts remotely
The exec command reads your file locally and ships its contents. No separate upload step is needed.
colab exec -f train.py exec runs Python from stdin, a .py file, or a notebook.
Step 5
Retrieve models and logs
Pull results back to your machine after the run.
colab download -s NAME checkpoints/model.bin ./model.bin
colab log -o report.ipynb Logs export as .ipynb, .md, .txt, or .jsonl.
Step 6
Example: fine-tune Gemma 3 1B
Google’s blog shows an agent running a QLoRA pipeline on a Text-to-SQL dataset.
colab new --gpu T4
colab install transformers datasets peft trl bitsandbytes accelerate
colab exec -f finetune_run.py
colab log --output gemma_finetune_log.ipynb
colab stop Step 7
Built for AI agents
- Any agent with terminal access can call the CLI.
- It works with Claude Code, Codex, and Antigravity.
- A bundled COLAB_SKILL.md gives agents built-in context.
- The result: scriptable, agent-ready Colab compute.