Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt

Use this file to discover all available pages before exploring further.

Authentication issues

Symptom: CWSandboxAuthenticationError or WandbAuthError raised on sandbox operations. The SDK resolves authentication in this order:
  1. CWSANDBOX_API_KEY env var (takes priority) - a CoreWeave API Access Token
  2. WANDB_API_KEY + WANDB_ENTITY_NAME env vars
  3. ~/.netrc (api.wandb.ai) + WANDB_ENTITY_NAME
You need one of these configured. Check which method you’re using:
# Option 1: CoreWeave API Access Token (recommended)
echo $CWSANDBOX_API_KEY

# Option 2: W&B credentials
echo $WANDB_API_KEY
echo $WANDB_ENTITY_NAME

Common issues

IssueSolution
No credentials configuredSet CWSANDBOX_API_KEY or W&B credentials
Invalid or expired tokenCreate a new API Access Token from the Cloud Console
W&B API key set but entity missingSet WANDB_ENTITY_NAME to your W&B entity/team
Using netrc but entity missingSet WANDB_ENTITY_NAME - it’s always required for W&B
Netrc parse errorsCheck ~/.netrc file syntax and permissions

Command execution issues

Timeout tuning

The SDK has two types of timeouts:
TimeoutScopeDefaultWhere set
timeout_secondsPer-execNoneexec() parameter
max_lifetime_secondsSandbox lifetimeBackend-controlledSandboxDefaults
Client-side timeout (timeout_seconds):
from cwsandbox import SandboxTimeoutError

try:
    result = sandbox.exec(
        ["python", "slow_script.py"],
        timeout_seconds=60.0,  # 60 second timeout
    ).result()
except SandboxTimeoutError:
    print("Command timed out")
Server-side lifetime (max_lifetime_seconds):
from cwsandbox import SandboxDefaults

defaults = SandboxDefaults(
    container_image="python:3.11",
    max_lifetime_seconds=3600,  # Sandbox terminates after 1 hour
)

Long-running commands

Issue: Command takes longer than expected. Solutions:
  1. Set appropriate timeout:
process = sandbox.exec(
    ["pip", "install", "tensorflow"],
    timeout_seconds=300.0,  # 5 minutes for large packages
)
result = process.result()
  1. Use streaming to monitor progress:
process = sandbox.exec(["pip", "install", "tensorflow"])

for line in process.stdout:
    print(line, end="")

result = process.result()

Exit code interpretation

Issue: Understanding command failures. Exit codes follow Unix conventions:
CodeMeaning
0Success
1General error
2Misuse of command
126Command not executable
127Command not found
128+NKilled by signal N
Use check=True to raise on non-zero exit:
from cwsandbox import SandboxExecutionError

try:
    result = sandbox.exec(
        ["python", "-c", "import nonexistent"],
        check=True,
    ).result()
except SandboxExecutionError as e:
    print(f"Exit code: {e.exec_result.returncode}")
    print(f"stderr: {e.exec_result.stderr}")

Streaming output issues

Line buffering behavior

Issue: Output appears delayed or all at once when streaming. Python buffers stdout when not connected to a TTY. Force unbuffered output:
# Option 1: Use -u flag
process = sandbox.exec(["python", "-u", "script.py"])
for line in process.stdout:
    print(line, end="")
result = process.result()

# Option 2: Set PYTHONUNBUFFERED
process = sandbox.exec(["sh", "-c", "PYTHONUNBUFFERED=1 python script.py"])
for line in process.stdout:
    print(line, end="")
result = process.result()
For your own scripts, flush explicitly:
print("Progress...", flush=True)

Cleanup problems

Orphaned sandboxes

Issue: Sandboxes remain running after script exits or crashes. Prevention: Use context managers:
# Recommended: automatic cleanup
with Sandbox.run() as sandbox:
    result = sandbox.exec(["echo", "hello"]).result()
# Sandbox stopped automatically
See Cleanup patterns: orphan management for how to find and clean up orphaned sandboxes by tag.

Common error messages

ErrorCauseSolution
CWSandboxAuthenticationErrorMissing or invalid credentialsCheck CWSANDBOX_API_KEY is set
WandbAuthError: WANDB_ENTITY_NAME is not setW&B API key found but entity missingSet WANDB_ENTITY_NAME env var
SandboxNotRunningErrorOperation on stopped sandboxCheck sandbox.status before operations
SandboxTimeoutErrorOperation exceeded timeoutIncrease timeout_seconds or optimize command
SandboxTerminatedErrorSandbox killed externallyCheck max_lifetime_seconds or external termination
SandboxFailedErrorSandbox failed to startCheck container image and resources
SandboxNotFoundErrorSandbox deleted or never existedVerify sandbox ID is correct
SandboxExecutionErrorCommand returned non-zero (with check=True)Check e.exec_result.stderr for details
SandboxFileErrorFile operation failedCheck file path and permissions
FunctionSerializationErrorCan’t serialize function argsUse JSON-serializable types or Serialization.PICKLE
AsyncFunctionErrorAsync function passed to @session.function()Use sync functions only
Last modified on April 21, 2026