Skip to content

feat: Add --env KEY=VALUE flag to colab run and colab exec to inject environment variables#65

Open
mvanhorn wants to merge 1 commit into
googlecolab:mainfrom
mvanhorn:fix/48-run-exec-env-flag
Open

feat: Add --env KEY=VALUE flag to colab run and colab exec to inject environment variables#65
mvanhorn wants to merge 1 commit into
googlecolab:mainfrom
mvanhorn:fix/48-run-exec-env-flag

Conversation

@mvanhorn

Copy link
Copy Markdown

Summary

google.colab.userdata.get() throws TimeoutException in CLI mode, so users have no clean way to pass secrets (HF_TOKEN, WANDB_API_KEY, etc.) to scripts run via colab run/colab exec. The reporter lists three options; maintainer teeler (CONTRIBUTOR, commented 2026-06-15) acknowledged it as a known issue and tagged the full userdata-API fix for later work because secrets are a separate backend API.

Changes

Add a repeatable --env KEY=VALUE typer.Option (List[str]) to run_command in run.py and to exec_command in execution.py. Parse each entry into a dict (splitting on the first '='), validate the key, and prepend an os.environ-setup prelude to the executed code.

Fixes #48

@teeler

teeler commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Clever, I think this is probably fine. I worry a little about notebook drift - notebooks using the userdata api can't also use env vars and vice versa.

But, if this scratches that itch for cli users then it seems reasonable to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Support Colab Secrets (userdata) in CLI mode

2 participants