Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.declaw.ai/llms.txt

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

Prerequisites

  • A Declaw Cloud account — sign up at declaw.ai to get an API key
  • DECLAW_API_KEY and DECLAW_DOMAIN environment variables set (see Deployment)
Enterprise on-prem customers receive their own DECLAW_DOMAIN from the Declaw team during provisioning. Everything else in this guide is identical.
1

Install the SDK

pip install declaw
Requires Python 3.10 or later. The package includes both synchronous (Sandbox) and asynchronous (AsyncSandbox) clients.
2

Set environment variables

export DECLAW_API_KEY="your-api-key"
export DECLAW_DOMAIN="your-declaw-instance.example.com:8080"
DECLAW_DOMAIN is the hostname of the Declaw API server (api.declaw.ai for Declaw Cloud). DECLAW_API_KEY authenticates your requests. Both are picked up automatically by the SDK — you do not need to pass them explicitly to Sandbox.create().
Get your API key from your dashboard at declaw.ai. Enterprise on-prem customers will receive their own domain and key.
3

Create a sandbox and run a command

from declaw import Sandbox

sbx = Sandbox.create(template="python", timeout=300)
try:
    result = sbx.commands.run('echo "Hello from Declaw!"')
    print(result.stdout)   # Hello from Declaw!
    print(result.exit_code)  # 0
finally:
    sbx.kill()
Sandbox.create() boots a sandbox and returns once the VM is ready. commands.run() executes the command inside the VM and blocks until it completes. sbx.kill() destroys the VM and releases all resources.
4

Write a file and run a script

from declaw import Sandbox

sbx = Sandbox.create(template="python", timeout=300)
try:
    # Write a Python script into the sandbox filesystem
    sbx.files.write("/tmp/hello.py", "print('Hello from inside the VM!')\n")

    # Execute it
    result = sbx.commands.run("python3 /tmp/hello.py")
    print(result.stdout)  # Hello from inside the VM!
finally:
    sbx.kill()
5

Add a security policy

Attach a SecurityPolicy at creation time to enable PII redaction, prompt injection defense, network restrictions, and audit logging.
from declaw import Sandbox, SecurityPolicy, PIIConfig, ALL_TRAFFIC

policy = SecurityPolicy(
    pii=PIIConfig(
        enabled=True,
        types=["ssn", "credit_card", "email", "phone"],
        action="redact",
    ),
    injection_defense=True,
    network={"allow_out": ["api.openai.com", "pypi.org"], "deny_out": [ALL_TRAFFIC]},
    audit=True,
)

sbx = Sandbox.create(template="python", timeout=300, security=policy)
try:
    result = sbx.commands.run("python3 -c 'print(2 + 2)'")
    print(result.stdout)  # 4
finally:
    sbx.kill()
With this policy:
  • Any HTTP request leaving the sandbox that contains a credit card number, SSN, email address, or phone number will have those values replaced with [REDACTED_*] tokens before reaching the external server.
  • The injection defense model scores every outbound LLM API call and blocks requests above the detection threshold.
  • Only api.openai.com and pypi.org can be reached. All other outbound connections are dropped.
  • Every security event is written to the audit log.
6

Next steps

You have created a sandbox, run commands and filesystem operations, and applied a security policy. Where to go next:
  • Concepts — understand the architecture: sandbox VMs, envd, the security proxy, and how they fit together.
  • Installation — detailed SDK setup, ConnectionConfig, and all configuration options.
  • Security overview — the full SecurityPolicy object and all available security controls.
  • Cookbook — 49 working examples covering LLM integrations, framework adapters, PII rehydration, agent-in-sandbox patterns, and security demos.