CLI tool for Google Colab - execute code and interact with Colab from the terminal
Project description
colabsh
A CLI tool for Google Colab. Execute code, download notebooks, and interact with Google Colab from the terminal. Connects to Google Colab through your browser via WebSocket — no API keys needed.
Table of Contents
- Installation
- Quick Start
- How It Works
- Commands
- Headless Mode
- Security
- Configuration
- Development
- Architecture
- License
Installation
| Method | Command |
|---|---|
| pip | pip install colabsh |
| uvx (no install) | uvx colabsh exec "print('hello')" |
| From source | git clone https://github.com/onuralpszr/colabsh.git && cd colabsh && uv sync |
Quick Start
# Start the server (opens Google Colab in browser once)
colabsh start
# Execute code (reuses the same browser tab)
colabsh exec "print('hello from Google Colab')"
colabsh exec -f script.py
echo "import sys; print(sys.version)" | colabsh exec -
# Interactive REPL with readline history
colabsh repl
# Download notebook
colabsh download notebook.ipynb
colabsh download script.py -f analysis.py
# Stop the server when done
colabsh stop
How It Works
Terminal Background Server Browser
──────── ───────────────── ───────
colabsh start ──────────────▶ WebSocket server ◀──────────▶ Colab
colabsh exec "code" ────TCP──▶ routes to Colab ──────────▶ executes
colabsh exec "more" ────TCP──▶ same connection ──────────▶ executes
colabsh stop ───────────────▶ shuts down
colabsh startlaunches a background server and opens Colab in your browser- Colab's frontend connects back via WebSocket (MCP proxy protocol)
- All subsequent commands go through this persistent connection
- One browser tab serves all commands — no new tabs per command
- The server auto-starts if you run
exec/replwithout starting first
Commands
Server
| Command | Description |
|---|---|
colabsh start |
Start server and open browser |
colabsh start --headless |
Print URL instead of opening browser |
colabsh start --qr |
Print QR code + URL for easy copy-paste |
colabsh stop |
Stop the background server |
colabsh status |
Check connection state |
Execute
| Command | Description |
|---|---|
colabsh exec "code" |
Execute inline code |
colabsh exec -f script.py |
Execute a file |
echo "code" | colabsh exec - |
Execute from stdin |
colabsh repl |
Interactive REPL |
REPL Features
| Feature | Details |
|---|---|
| Arrow keys | Navigate previous commands (readline history) |
| Persistent history | Saved across sessions |
| Multiline input | Lines ending with : or \ start a block (end with empty line) |
| Commands | /quit, /tools, /cells |
Download
| Command | Description |
|---|---|
colabsh download notebook.ipynb |
Download as Jupyter notebook |
colabsh download script.py |
Download as Python script |
colabsh download output.ipynb -f analysis.py |
Execute first, then download with results |
Other
| Command | Description |
|---|---|
colabsh tools |
List available Google Colab frontend tools |
colabsh history list |
Show tracked sessions |
colabsh history show <id> |
Show detailed history for a notebook |
colabsh history clear |
Delete all local history |
colabsh history toggle [on|off] |
Enable/disable local history tracking |
colabsh history path |
Show history file path |
colabsh --json <command> |
JSON output for scripting/LLM tools |
colabsh -v <command> |
Enable debug logging |
Headless Mode
For SSH sessions, containers, or remote machines where there's no desktop browser:
colabsh start --headless
This prints the connection URL instead of opening a browser. Open the URL on the same machine in any browser.
SSH Port Forwarding
To use colabsh on a remote server:
# On remote server
colabsh start --headless
# Output: https://colab.research.google.com/notebooks/empty.ipynb#mcpProxyToken=...&mcpProxyPort=45123
# On your local machine (forward the port)
ssh -L 45123:localhost:45123 remote-server
# Open the printed URL in your local browser
# It connects to localhost:45123 which is forwarded to the remote server
# Now run commands on the remote server
colabsh exec "print('running on remote')"
Why not LAN/phone access? Google Colab's frontend JavaScript always connects WebSocket to
localhost— this is hardcoded in Google's code. When you open the URL on a different device, the browser tries to connect tolocalhoston that device, which doesn't have the colabsh server. The only workaround is SSH port forwarding, which makes the remote port appear aslocalhoston your local machine.
Security
What colabsh does
- Runs a localhost-only WebSocket server — not accessible from the network
- Uses a random authentication token for every session
- Communicates with Google Colab via Google's MCP proxy protocol
- Stores data locally in your config directory — nothing is sent to third parties
What to be aware of
- The connection URL contains a secret token — treat it like a password
- Anyone with the URL can execute code in your Colab session
- The background server runs until you stop it (
colabsh stop) - Code execution happens on Google's Colab VMs, subject to Google's terms of service
- The Google Colab session has your Google account's permissions
Token lifecycle
| Event | Behavior |
|---|---|
colabsh start |
A new random token is generated |
| While running | Token stored in ~/.config/colabsh/server.json (user-readable only) |
colabsh stop |
Token is deleted |
Configuration
Config directory
| Platform | Path |
|---|---|
| Linux | ~/.config/colabsh/ |
| macOS | ~/Library/Application Support/colabsh/ |
| Windows | C:\Users\<user>\AppData\Roaming\colabsh\ |
Config files
| File | Description |
|---|---|
server.json |
Running server state (port, PID, token) |
server.log |
Server logs |
settings.json |
User preferences (headless mode, etc.) |
history.json |
Local usage history |
repl_history |
Readline command history |
Output format
Human-readable output is the default:
colabsh status
# status: running
# connected: true
# pid: 12345
colabsh --json status
# {"status": "running", "connected": true, "pid": 12345}
Use --json when piping to other tools or LLMs.
Development
| Task | Command |
|---|---|
| Install dependencies | uv sync |
| Run tests | uv run pytest |
| Lint | uv run ruff check src/ tests/ |
| Format | uv run ruff format src/ tests/ |
| Type check | uv run mypy src/colabsh/ |
Architecture
src/colabsh/
├── main.py # Click CLI entry point
├── commands.py # All commands (exec, repl, start, stop, download, tools)
├── history.py # history list/show/clear/toggle
└── core/
├── config.py # Platform config dirs, settings
├── server.py # Background server (WebSocket + TCP control)
├── proxy.py # WebSocket + JSON-RPC to Colab frontend
├── output.py # JSON/human formatter
├── history.py # Local usage tracking
├── repl.py # Shared REPL with readline
└── qr.py # QR code generation (optional)
License
Apache-2.0
Inspiration
Inspired by colab-mcp-proxy but with a focus on CLI usability, persistent server, and local history.
Disclaimer
This project has no affiliation with Google. It reverse-engineers Google Colab's frontend protocol to enable terminal access. Use responsibly and in accordance with Google's terms of service.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file colabsh-1.0.1.tar.gz.
File metadata
- Download URL: colabsh-1.0.1.tar.gz
- Upload date:
- Size: 1.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f02ced7a5241775c41d3cf0ce2238469a2965f35815c2e3a48bf9b549643146
|
|
| MD5 |
5ad4b7597b0517ed71988c0eba253052
|
|
| BLAKE2b-256 |
483ad2ba1ffbe3dd5ab2f19f7679c7f41567bbdd5f8f04035f42109c0dccd95e
|
Provenance
The following attestation bundles were made for colabsh-1.0.1.tar.gz:
Publisher:
release.yml on onuralpszr/colabsh
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
colabsh-1.0.1.tar.gz -
Subject digest:
2f02ced7a5241775c41d3cf0ce2238469a2965f35815c2e3a48bf9b549643146 - Sigstore transparency entry: 1154914481
- Sigstore integration time:
-
Permalink:
onuralpszr/colabsh@3d5d571924134f3396bdcf89a466fd63249a4d40 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/onuralpszr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3d5d571924134f3396bdcf89a466fd63249a4d40 -
Trigger Event:
push
-
Statement type:
File details
Details for the file colabsh-1.0.1-py3-none-any.whl.
File metadata
- Download URL: colabsh-1.0.1-py3-none-any.whl
- Upload date:
- Size: 30.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba093be29c52794cad7f2589668a2734699a3582b829cb5861922987f66b9749
|
|
| MD5 |
c983524e8ccc68a163199c47e7c7db51
|
|
| BLAKE2b-256 |
a1bbd4475ef01750814edf47dc87ce8664ca601318b17d5eb23ca96100ff2393
|
Provenance
The following attestation bundles were made for colabsh-1.0.1-py3-none-any.whl:
Publisher:
release.yml on onuralpszr/colabsh
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
colabsh-1.0.1-py3-none-any.whl -
Subject digest:
ba093be29c52794cad7f2589668a2734699a3582b829cb5861922987f66b9749 - Sigstore transparency entry: 1154914485
- Sigstore integration time:
-
Permalink:
onuralpszr/colabsh@3d5d571924134f3396bdcf89a466fd63249a4d40 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/onuralpszr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3d5d571924134f3396bdcf89a466fd63249a4d40 -
Trigger Event:
push
-
Statement type: