Skip to main content
Use W&B Secret Manager to make API tokens and other credentials available inside a serverless sandbox. Your application passes secret names to the Sandbox API. When the API creates the sandbox, it resolves the values from your W&B team and injects them as environment variables.
CoreWeave Serverless sandboxes are in public preview.

Before you begin

W&B secret injection requires a sandbox authenticated with a W&B API key. It’s available for serverless sandboxes, but not for sandboxes on your own CoreWeave Kubernetes Service (CKS) cluster. CKS placement uses a CoreWeave API access token. You can’t combine that token with a separate W&B key to resolve secrets for a CKS sandbox. To follow the examples, you need the following:
  • A W&B software-as-a-service (SaaS) account with serverless sandbox access.
  • A secret named HF_TOKEN in your W&B team’s Secret Manager. If the secret doesn’t exist, ask a W&B administrator to add the secret.
  • A W&B API key with access to that team.
Set WANDB_API_KEY in the environment of the process that creates the sandbox. Replace [WANDB-API-KEY] with your W&B API key:
WANDB_ENTITY is optional and defaults to the API key’s default entity. If the secret belongs to another team, set WANDB_ENTITY to that team. Replace [WANDB-TEAM] with the team name:
Install the client for your language:
Use Python 3.11 or later and install uv if needed. In your Python environment, install the client with its W&B authentication dependency:

Inject a secret

Use store="wandb" in Python or store: "wandb" in TypeScript. This store resolves secrets for the authenticated W&B team. You don’t need to register an organization secret store for this flow. The following examples inject HF_TOKEN and check that it’s present without printing its value. In the sandbox, the environment variable defaults to the secret’s name.
Select W&B authentication explicitly with AuthStrategy.WANDB:
Both examples print Secret is available and stop the sandbox when the operation finishes. Code running inside the sandbox can read the value from HF_TOKEN. Pass the secret’s name, not its value, in secrets. The server resolves the value. Don’t print it or write it to logs.

Secret reference fields

Use these fields in a Python Secret or a TypeScript secrets entry:

Use a custom environment variable name

To choose the environment variable that receives the secret, set env_var in Python or envVar in TypeScript. The following examples expose the HF_TOKEN secret as HUGGINGFACE_TOKEN:
Both examples print Secret is available after they check that HUGGINGFACE_TOKEN is present.

Select a field from a structured secret

To inject one value from a JSON object, set field to its top-level key. Nested paths aren’t supported. For a JSON string, the injected value has no surrounding JSON quotes. For this example, add a team secret named DB_CREDENTIALS whose value is a JSON object such as {"password":"[DB-PASSWORD]"}. Replace [DB-PASSWORD] with the password before you save the secret. The examples inject its password field into DB_PASSWORD:
Both examples print Secret is available without printing the password. Selecting a field fails if the secret isn’t a JSON object, the key doesn’t exist, or its value is null.

Reuse secret references

For Python sessions, put shared secret references in SandboxDefaults. For TypeScript, reuse a secrets array when you create sandboxes:
The Python client merges session defaults with per-sandbox secrets and ignores exact duplicates. If different references target the same environment variable, the client raises ValueError before it creates the sandbox. For the Python type signature, see the Secret reference.

Troubleshoot secret injection

If the sandbox fails to start with a secret reference, use the error text to check authentication, the selected team, and placement: W&B secret injection isn’t available for CKS placement, including when you set both a CoreWeave API access token and a W&B API key.
Last modified on September 18, 2026