CoreWeave Sandbox Python Client

0.16.0 · active · verified Sun Apr 12

A Python client library for CoreWeave Sandboxes (CWSandboxes), offering a programmatic interface to manage sandboxed environments for secure execution of workloads on the CoreWeave platform. It is currently at version 0.16.0 and maintains an active release cadence with frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create and run a simple command within a CoreWeave Sandbox using the `cwsandbox` client library. It highlights the use of `Sandbox.run` to initiate a sandbox and `sb.stop().result()` to wait for its completion and retrieve the output. Authentication typically relies on environment variables or a configured CoreWeave client.

import os
from cwsandbox import Sandbox

# Ensure COREWEAVE_API_KEY and COREWEAVE_PROJECT_ID (or similar) are set in your environment
# For demonstration, using dummy values. In production, use actual credentials.
# os.environ['COREWEAVE_API_KEY'] = os.environ.get('CWSANDBOX_API_KEY', 'your_api_key_here')
# os.environ['COREWEAVE_PROJECT_ID'] = os.environ.get('CWSANDBOX_PROJECT_ID', 'your_project_id_here')

try:
    # Create and run a simple command in a sandbox
    print("Starting sandbox...")
    sb = Sandbox.run("echo", "Hello, World! from cwsandbox")
    print(f"Sandbox ID: {sb.id}")

    # Wait for the sandbox to complete and get results (synchronous wait)
    result = sb.stop().result()
    print("Sandbox output:")
    print(result.output)
    print(f"Sandbox exited with code: {result.exit_code}")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Ensure your CoreWeave environment is configured and authenticated.")

view raw JSON →