Skip to main content

Requirements

SDKRuntime requirement
PythonPython 3.10 or later
TypeScriptNode.js 18 or later
You also need a Declaw API key. Sign up at declaw.ai to use Declaw Cloud, or see the Deployment overview for enterprise on-prem options.

Install

This installs both the synchronous (Sandbox) and asynchronous (AsyncSandbox) clients, along with all security policy types and model classes.To install a specific version:
pip install "declaw==0.1.0"
To add it to a pyproject.toml project:
uv add declaw
# or
poetry add declaw

Configuration

The SDK connects to a Declaw API server. You configure the connection either through environment variables (recommended) or programmatically via ConnectionConfig.

Environment variables

VariableDescription
DECLAW_API_KEYAPI key sent as the X-API-Key header on every request. Get one from your dashboard at declaw.ai.
DECLAW_DOMAINHostname of the Declaw API server. Defaults to api.declaw.ai for Declaw Cloud. Enterprise on-prem customers will receive their own domain. Do not include the https:// scheme.
When these variables are set, you can call Sandbox.create() without any arguments:
from declaw import Sandbox

# Picks up DECLAW_API_KEY and DECLAW_DOMAIN from the environment
sbx = Sandbox.create(template="python", timeout=300)
sbx.kill()

Explicit ConnectionConfig

Pass a ConnectionConfig directly when you need multiple connections, non-standard ports, or explicit control over credentials:
from declaw import Sandbox, ConnectionConfig

config = ConnectionConfig(
    api_key="your-api-key",
    domain="my-vm.example.com:8080",
)

sbx = Sandbox.create(template="python", timeout=300, connection_config=config)
sbx.kill()

Timeout

The timeout parameter on Sandbox.create() sets the maximum lifetime of the sandbox in seconds. If the sandbox is not killed before the timeout, the server destroys it automatically. The default is 300 seconds (5 minutes).
Always call sbx.kill() in a finally block. If your process crashes before calling kill(), the sandbox lives until its timeout expires and continues consuming server resources.

Verify your setup

After installing the SDK and setting your environment variables, run a quick smoke test:
from declaw import Sandbox

sbx = Sandbox.create(template="python", timeout=60)
try:
    result = sbx.commands.run("uname -a")
    print(result.stdout)
    assert result.exit_code == 0
    print("Declaw is working correctly.")
finally:
    sbx.kill()
If you see a Linux kernel string in the output, your SDK is connected and sandboxes are booting correctly.

Common errors

ErrorCauseFix
AuthenticationExceptionDECLAW_API_KEY is missing or invalidSet the correct key in your environment or ConnectionConfig
Connection refusedDECLAW_DOMAIN points to an unreachable serverVerify the server is running and the domain/port are correct
NotFoundExceptionSandbox ID does not exist (e.g., it already timed out)Re-create the sandbox; check your timeout value
TimeoutExceptionA command exceeded its timeoutIncrease timeout on commands.run() or break the work into smaller steps

Next steps