For years, developers and data scientists have had to choose between the robust IDE features of VS Code and the free, high-powered, and easy-to-provision runtimes of Google Colab. Thanks to the new official Google Colab extension for VS Code, that trade-off is over.
This integration finally bridges the gap, allowing you to use VS Code’s powerful editing features (Git integration, advanced debugging, extensibility) while running your Jupyter notebooks on Colab’s cloud resources, including premium GPUs and TPUs [01:12].
Here is your step-by-step guide to connecting your local or Codespaces environment to a Google Colab runtime.
Why Integrate Colab with VS Code?
The new integration provides the ideal environment for large-scale or collaborative projects [01:30]:
| Platform Strength | Benefit in Integration |
| VS Code | Full IDE experience, powerful Git integration, advanced editing, file explorer, and extensibility. |
| Google Colab | Easy, fast provisioning of high-powered, free runtimes, including NVIDIA T4 GPUs and TPUs [01:12]. |
This allows you to keep your project structure and code in a local repository while offloading the computational work (like model training) to Google’s cloud infrastructure.
Step-by-Step Tutorial: Connecting to Colab
The process requires installing two extensions and securely logging into your Google account.
Step 1: Install Required Extensions
- Open the Extensions view in VS Code (
Ctrl+Shift+XorCmd+Shift+X). - Search for and install the Jupyter extension. This is a prerequisite for notebook functionality [03:07].
- Search for and install the Colab extension. Crucially, ensure it is published by Google to confirm it is the official version [03:43].
- When prompted, click “Trust publisher and Install” [04:07].
Step 2: Create and Select the Colab Kernel
- In your Explorer view, create a new file named with the Jupyter extension, such as
test.ipynb[04:23]. - Once the notebook opens, look for the kernel selector (usually in the top-right corner) and click it.
- Select “Select another Kernel” [04:54].
- Choose the Colab option [05:01].
Step 3: Authorize Your Google Account (First Time)
- The kernel selector will show three options; choose “Autoconnect” [05:14].
- VS Code will prompt you to sign in. Click “Allow” to let the extension use Google for sign-in [05:28].
- A browser window will open. Select your Google account and authorize the connection.
- You may be asked to copy a code from the browser and paste it back into VS Code [06:00].
- Once authorized, select the Python 3 kernel (or R/Julia, if desired) [06:33]. Your notebook is now running on a default Colab CPU runtime!
Step 4: Connect to a GPU or TPU Runtime (Optional)
If you need accelerated computing, you must explicitly select a new server:
- Go back to the kernel selector and choose “Select another Kernel” again.
- Choose the Colab option.
- This time, select “New Colab Server” [08:01].
- You will be prompted to choose your hardware accelerator: CPU, GPU, or TPU [08:21].
- Select GPU (or TPU) and then specify the type (e.g., T4 GPU) [08:26].
- Your notebook will now connect to the Colab GPU runtime, allowing you to execute computationally heavy code [08:51].
Step 5: Clean Up and Disconnect
โ ๏ธ Important: To avoid keeping a Colab runtime running unnecessarily, you must disconnect when you are finished [09:31].
- Open the Command Palette (
Ctrl+Shift+PorCmd+Shift+P). - Type “Colab: Remove Server” [09:31].
- Select the server(s) you wish to disconnect (e.g., “Colab CPU” or “Colab GPU”).
After disconnecting, your kernel will stop running, and you will have to reconnect to a runtime the next time you use the notebook.

Leave a Reply