Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The Kaggle CLI is organized into several command groups:
* [Competitions](./competitions.md): Manage and participate in Kaggle competitions.
* [Datasets](./datasets.md): Search, download, and manage Kaggle datasets.
* [Forums](./forums.md): Browse and read Kaggle discussion forums.
* [Kernels](./kernels.md): Interact with Kaggle Kernels (notebooks and scripts).
* [Kernels](./kernels.md): Interact with Kaggle Kernels (notebooks and scripts). Includes information on using [Kaggle Secrets](./kernels.md#using-secrets-in-kernels).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? We don't highlight the other sections.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should either have secrets mentioned here or listed as its own top-level item. I think this is fine, given our limitations on usage (only for notebooks run on kaggle.com).

* [Models](./models.md): Manage your Kaggle Models.
* [Model Variations](./model_variations.md): Manage variations of your Kaggle Models.
* [Model Variation Versions](./model_variations_versions.md): Manage versions of your Kaggle Model Variations.
Expand Down
21 changes: 21 additions & 0 deletions docs/kernels.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,24 @@ kaggle kernels topics show owner/kernel-slug/12345
**Purpose:**

This command displays a full discussion topic along with all of its comments rendered in an indented tree structure.

## Using Secrets in Kernels

If your kernel needs to access sensitive information (like API keys or passwords) without exposing them in your code, you should use **Kaggle Secrets**.

@rosbo rosbo Jul 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should highlight that secrets can't be defined via the CLI and you must define them in the notebook editor.

But I think what we really want is to have CLI support.

Is there a way to attach / detach a secret from the notebook using the CLI? Should we add one? (e.g. Should the kernels-metadata.json have a list of secrets to attach)

Should we add a way to set / delete secrets from the CLI? e.g. kaggle kernels secrets set HUGGING_FACE_HUB_TOKEN myTokenXyzValue.

The flow would be you create a secret with kaggle kernels secrets set KEY VALUE command. Then, you can add secrets = ['KEY'] in the kernels metadata.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLI support is an interesting idea to consider for V3, assuming that gets scheduled.

Maybe you should highlight that secrets can't be defined via the CLI and you must define them in the notebook editor.

Isn't that already done?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't necessarily need a V3 to support secrets given it is additive and non-breaking. But agree that this outside the scope of a fixit. Can you file a bug?

re: highlight

I agree it is implicit given the instructions mention using the kernel but given this is the CLI doc, I could see a user quickly skimming though may be confused because they are looking for the CLI command for secrets. I would consider adding at the top of this section: "Note: secrets are not supported by the CLI and you must use the Kernel editor". I will leave it up to you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. I adjust the wording a bit.


### 1. Define Secrets on Kaggle.com (no CLI support)
1. Open your notebook in the Kaggle Notebook Editor.
2. In the menu, select **Add-ons** -> **Secrets**.
3. Add your secrets as key-value pairs (e.g., Label: `MY_API_KEY`, Value: `your-actual-key-value`).

### 2. Use Secrets in your Code Running on Kaggle.com
Use the `UserSecretsClient` from the `kaggle_secrets` package to retrieve your secrets at runtime:

```python
from kaggle_secrets import UserSecretsClient

# Retrieve the secret value using the label you defined
secret_value = UserSecretsClient().get_secret("MY_API_KEY")
```

**Note:** The `kaggle_secrets` package is pre-installed and only functional within the Kaggle notebook execution environment. It will not work when running scripts locally.
Loading