Skip to main content
When you’re running a script in an automated environment, you can control W&B with environment variables set before the script runs or within the script. Use environment variables to configure authentication, project and run metadata, logging behavior, and storage locations without modifying your training code. This is useful for CI systems, batch jobs, and shared infrastructure. The following examples show common patterns for setting W&B environment variables in shell scripts and Python code.
# This is secret and shouldn't be checked into version control
WANDB_API_KEY=$YOUR_API_KEY
# Name and notes optional
WANDB_NAME="My first run"
WANDB_NOTES="Smaller learning rate, more regularization."
# Only needed if you don't check in the wandb/settings file
WANDB_ENTITY=$username
WANDB_PROJECT=$project
# If you don't want your script to sync to the cloud
os.environ["WANDB_MODE"] = "offline"

# Add sweep ID tracking to Run objects and related classes
os.environ["WANDB_SWEEP_ID"] = "b05fq58z"

Optional environment variables

Use these optional environment variables to do things such as set up authentication on remote machines. The following table lists each variable and how W&B uses it.
Variable nameUsage
WANDB_API_KEYSets the authentication key associated with your account. Create an API key at User Settings. You must set this if you haven’t run wandb login on the remote machine.
WANDB_BASE_URLIf you’re using wandb/local, set this environment variable to http://[YOUR_IP]:[YOUR_PORT].
WANDB_CACHE_DIRDefaults to ~/.cache/wandb. Use this environment variable to override the location.
WANDB_CONFIG_DIRDefaults to ~/.config/wandb. Use this environment variable to override the location.
WANDB_CONFIG_PATHSComma-separated list of YAML files to load into wandb.config. See config.
WANDB_CONSOLESet this to off to disable stdout/stderr logging. Defaults to on in environments that support it.
WANDB_DATA_DIRWhere to upload staging artifacts. The default location depends on your platform, because it uses the value of user_data_dir from the platformdirs Python package. Make sure this directory exists and the running user has permission to write to it.
WANDB_DIRWhere to store all generated files. If unset, defaults to the wandb directory relative to your training script. Make sure this directory exists and the running user has permission to write to it. This doesn’t control the location of downloaded artifacts, which you can set using the WANDB_ARTIFACT_DIR environment variable.
WANDB_ARTIFACT_DIRWhere to store all downloaded artifacts. If unset, defaults to the artifacts directory relative to your training script. Make sure this directory exists and the running user has permission to write to it. This doesn’t control the location of generated metadata files, which you can set using the WANDB_DIR environment variable.
WANDB_DISABLE_GITPrevents W&B from probing for a Git repository and capturing the latest commit and diff.
WANDB_DISABLE_CODESet this to true to prevent W&B from saving notebooks or Git diffs. W&B still saves the current commit if you’re in a Git repo.
WANDB_DOCKERSet this to a Docker image digest to enable restoring of runs. This is set automatically with the wandb docker command. You can obtain an image digest by running wandb docker [IMAGE_NAME]:[TAG] --digest.
WANDB_ENTITYThe entity associated with your run. If you have run wandb init in the directory of your training script, W&B creates a directory named wandb and saves a default entity, which you can check into source control. If you don’t want to create that file or want to override the file, use the environment variable.
WANDB_ERROR_REPORTINGSet this to false to prevent W&B from logging fatal errors to its error tracking system.
WANDB_HOSTSet this to the hostname you want to see in the W&B interface if you don’t want to use the system-provided hostname.
WANDB_IGNORE_GLOBSSet this to a comma-separated list of file globs to ignore. W&B doesn’t sync these files to the cloud.
WANDB_JOB_NAMESpecifies a name for any jobs created by W&B.
WANDB_JOB_TYPESpecifies the job type, such as training or evaluation, to indicate different types of runs. See grouping for more info.
WANDB_MODEIf you set this to offline, W&B saves your run metadata locally and doesn’t sync to the server. If you set this to disabled, W&B turns off completely.
WANDB_NAMEThe human-readable name of your run. If not set, W&B randomly generates it for you.
WANDB_NOTEBOOK_NAMEIf you’re running in Jupyter, you can set the name of the notebook with this variable. W&B attempts to autodetect this.
WANDB_NOTESLonger notes about your run. Markdown is allowed, and you can edit this later in the UI.
WANDB_PROJECTThe project associated with your run. You can also set this with wandb init, but the environment variable overrides the value.
WANDB_RESUMEBy default, this is set to never. If set to auto, W&B automatically resumes failed runs. If set to must, forces the run to exist on startup. If you want to always generate your own unique IDs, set this to allow and always set WANDB_RUN_ID.
WANDB_RUN_GROUPSpecifies the experiment name to automatically group runs together. See grouping for more info.
WANDB_RUN_IDSet this to a globally unique string (per project) corresponding to a single run of your script. It must be no longer than 64 characters. W&B converts all non-word characters to dashes. You can use this to resume an existing run in cases of failure.
WANDB_QUIETSet this to true to limit statements logged to standard output to critical statements only. If this is set, W&B writes all logs to $WANDB_DIR/debug.log.
WANDB_SILENTSet this to true to silence wandb log statements. This is useful for scripted commands. If this is set, W&B writes all logs to $WANDB_DIR/debug.log.
WANDB_SHOW_RUNSet this to true to automatically open a browser with the run URL if your operating system supports it.
WANDB_SWEEP_IDAdds sweep ID tracking to Run objects and related classes, and displays it in the UI.
WANDB_TAGSA comma-separated list of tags to apply to the run.
WANDB_USERNAMEThe username of a member of your team associated with the run. Use this along with a service account API key to enable attribution of automated runs to members of your team.
WANDB_USER_EMAILThe email of a member of your team associated with the run. Use this along with a service account API key to enable attribution of automated runs to members of your team.

Singularity environments

If you’re running containers in Singularity, you can pass environment variables by prepending any of the previous variables with SINGULARITYENV_. For more details about Singularity environment variables, see the Singularity documentation.

Run on AWS

If you’re running batch jobs in AWS, you can authenticate your machines with your W&B credentials. Create an API key at User Settings, and set the WANDB_API_KEY environment variable in the AWS batch job spec.