Skip to main content
The examples on this page omit auth. To authenticate with your W&B API key, install cwsandbox[wandb] and pass auth=AuthStrategy.WANDB to Sandbox.run(), Sandbox(), or Sandbox.session(). See Get started.
This guide shows you how to set and manage environment variables in CWSandbox instances. Use environment variables to pass non-sensitive configuration values, such as log levels or project identifiers, into your sandboxes. You can set them on individual sandboxes, share them across sandboxes in a session, or scope them to remote functions.
Don’t hardcode API keys, passwords, or other credentials in environment_variables, or print them to logs. Prefer secret references over passing raw credentials. Keep sensitive values in a secret manager, even when W&B secret injection isn’t available. This guidance applies to both serverless and CKS sandboxes.
W&B で認証したサーバーレスのサンドボックスでは、W&B シークレットを使用してください。これらの参照はサーバー側で解決され、その値が環境変数として注入されます。W&B シークレット注入は、CKS に配置する場合や、CoreWeave API アクセストークンで認証したサンドボックスでは利用できません。CKS では、ワークロードにシークレットを渡す方法として組織で承認されている手段を使用してください。

Basic usage

To make values available to processes running inside the sandbox, pass an environment_variables dictionary to Sandbox.run:

Session-level defaults

When you need the same variables in several sandboxes, define them once on a session instead of repeating them per sandbox. Individual sandboxes can override session defaults or add their own variables:

Remote functions

Remote functions inherit environment variables from the session and can declare their own through the @session.function decorator. The SDK merges function-level variables with session defaults at call time:
Environment variables are passed by reference. Subsequent function calls reflect mutations to the dictionary after decoration, as shown in the following example.
最終更新日 2026年9月30日