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일