{"id":5600,"library":"cwsandbox","title":"CoreWeave Sandbox Python Client","description":"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.","status":"active","version":"0.16.0","language":"en","source_language":"en","source_url":"https://github.com/coreweave/cwsandbox-client","tags":["cloud","coreweave","sandbox","api-client","remote-execution"],"install":[{"cmd":"pip install cwsandbox","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"Sandbox","correct":"from cwsandbox import Sandbox"}],"quickstart":{"code":"import os\nfrom cwsandbox import Sandbox\n\n# Ensure COREWEAVE_API_KEY and COREWEAVE_PROJECT_ID (or similar) are set in your environment\n# For demonstration, using dummy values. In production, use actual credentials.\n# os.environ['COREWEAVE_API_KEY'] = os.environ.get('CWSANDBOX_API_KEY', 'your_api_key_here')\n# os.environ['COREWEAVE_PROJECT_ID'] = os.environ.get('CWSANDBOX_PROJECT_ID', 'your_project_id_here')\n\ntry:\n    # Create and run a simple command in a sandbox\n    print(\"Starting sandbox...\")\n    sb = Sandbox.run(\"echo\", \"Hello, World! from cwsandbox\")\n    print(f\"Sandbox ID: {sb.id}\")\n\n    # Wait for the sandbox to complete and get results (synchronous wait)\n    result = sb.stop().result()\n    print(\"Sandbox output:\")\n    print(result.output)\n    print(f\"Sandbox exited with code: {result.exit_code}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Ensure your CoreWeave environment is configured and authenticated.\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Ensure `COREWEAVE_API_KEY` and `COREWEAVE_PROJECT_ID` (or equivalent CoreWeave client configuration) are correctly set in your environment before using the library. Refer to CoreWeave's official authentication documentation for details.","message":"Authentication to the CoreWeave platform is required. The `cwsandbox` client relies on proper configuration, often via environment variables (e.g., `COREWEAVE_API_KEY`, `COREWEAVE_PROJECT_ID`) or a configured CoreWeave CLI/SDK context. The provided quickstart assumes this setup.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Understand that `cwsandbox` is an API client for managing remote execution environments provided by CoreWeave. If you need to sandbox Python code locally, consider dedicated Python sandboxing tools or OS-level isolation (e.g., containers).","message":"The term 'cwsandbox' in this context refers to a client for CoreWeave's remote sandboxing service, not a local Python-level sandbox for executing untrusted Python code. Misunderstanding this distinction can lead to incorrect security assumptions if you intend to sandbox local Python execution.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always ensure that `sb.stop()` is called for any `Sandbox` instance you create, ideally within a `try...finally` block or by using a context manager if available, to guarantee resource cleanup.","message":"Failing to explicitly stop sandboxes (`sb.stop()`) can lead to resource leakage and unexpected billing, as sandbox instances on the CoreWeave platform may continue to run if not properly terminated.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For robust asynchronous applications, consult the official documentation (if available) for native async methods (e.g., `await Sandbox.arun()`, `await sb.astop()`) to avoid blocking the event loop. For synchronous applications, ensure you understand where blocking operations occur.","message":"The `Sandbox.run` factory method provides a hybrid synchronous/asynchronous API (`.result()` blocks). While convenient, mixing sync and async code can be a footgun. Older versions or alternative methods might have different blocking behaviors.","severity":"deprecated","affected_versions":"<0.16.0 (potential, check specific migration guides for earlier breaking changes related to async/sync patterns)"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}