Skip to main content
wandb.sandbox is deprecated and will be removed in a future release of the W&B Python SDK. Use the cwsandbox package instead, documented in the CoreWeave sandbox docs.Migrating changes two things:
  • The import. Install cwsandbox with the W&B extra (pip install "cwsandbox[wandb]") and import from cwsandbox instead of wandb.sandbox.
  • The credential. cwsandbox authenticates with a CoreWeave API access token in CWSANDBOX_API_KEY by default, so pass auth=AuthStrategy.WANDB to keep using your W&B API key. See Choose a credential.
The examples on this page still use wandb.sandbox. For the equivalent cwsandbox code, see Migrate to cwsandbox.
Serverless Sandboxes is in public preview. Access is enabled per organization. To request access for your organization, contact support.
In this tutorial, you invoke an agent in a W&B Serverless Sandbox. You start a sandbox with the required environment variables, install dependencies, and run a Python script that creates and invokes a simple OpenAI agent. The agent uses tool calls to get weather for a location and return a punny forecast.
This tutorial uses OpenAI as the language model for the agent, which requires an OpenAI API key.

Prerequisites

Before you begin, install the W&B Python SDK, authenticate with W&B, and store your OpenAI API key as a secret so the sandbox can use it.

Install W&B Python SDK

Install the W&B Python SDK using pip:

Log in and authenticate with W&B

Run the wandb login CLI command and follow the prompts to log in to your W&B account:

Store API keys in Secret Manager

Store your OpenAI API key in the W&B Secret Manager as OPENAI_API_KEY. For more information about using secrets in sandboxes, see Secrets. This lets you securely access the API key in the sandbox without hardcoding it in your code or sandbox configuration.

Copy agent code

With your prerequisites in place, save the agent code locally so you can run it inside a sandbox. The script defines an OpenAI agent with two tools and a structured response format.
Copy the following code into a file named demo.py in the same directory as this tutorial. Then, run the previous code snippet to invoke an OpenAI agent in a sandbox.
demo.py