Skip to main content
The Declaw TypeScript SDK is available on npm and targets Node.js 18+ and modern browsers with native fetch support.

Installation

npm install @declaw/sdk

Environment variables

export DECLAW_API_KEY="your-api-key"
export DECLAW_DOMAIN="api.declaw.ai"         # or your enterprise on-prem domain

ConnectionConfig

ConnectionConfig holds the API key, domain, port, and base URL. It is constructed automatically when you pass apiKey and domain to Sandbox.create(). Instantiate it directly when you need to share connection settings.
import { ConnectionConfig } from '@declaw/sdk';

const config = new ConnectionConfig({
  apiKey: 'your-api-key',
  domain: '104.198.24.180:8080',
  requestTimeout: 30_000, // ms
});

ConnectionConfigOptions

apiKey
string
API key sent as X-API-Key. Defaults to process.env.DECLAW_API_KEY.
domain
string
default:"process.env.DECLAW_DOMAIN or 'localhost'"
Hostname of the Declaw API. Supports host:port format — the port is parsed from the string.
port
number
default:"443"
Explicit port override. Ignored when domain already contains a port.
apiUrl
string
Full URL override (e.g. http://localhost:8080). When set, domain, port, and scheme detection are bypassed.
requestTimeout
number
Default per-request HTTP timeout in milliseconds.

Properties

PropertyTypeDescription
config.apiKeystringResolved API key.
config.domainstringResolved hostname (without port).
config.portnumberResolved port.
config.apiUrlstringFully constructed base URL.
config.requestTimeoutnumber | undefinedDefault timeout in ms.

SandboxOpts

SandboxOpts is the options object passed to Sandbox.create().
import { Sandbox } from '@declaw/sdk';

const sbx = await Sandbox.create({
  template: 'base',
  timeout: 300,
  envs: { MY_VAR: 'hello' },
  apiKey: 'your-api-key',
  domain: '104.198.24.180:8080',
});
template
string
default:"'base'"
Template ID or alias to boot.
timeout
number
default:"300"
Sandbox lifetime in seconds.
metadata
Record<string, string>
Arbitrary key-value pairs attached to the sandbox.
envs
Record<string, string>
Environment variables injected at boot time.
secure
boolean
default:"true"
Whether to enable the MITM security proxy.
allowInternetAccess
boolean
default:"true"
When false, blocks all outbound traffic (deny_out: ["0.0.0.0/0"]).
network
SandboxNetworkOpts
Fine-grained network configuration. Overrides allowInternetAccess.
security
SecurityPolicy
Full security policy. See Security Policy.
resources
Record<string, unknown>
Resource constraints (e.g. { cpu: 2, memory_mb: 2048 }).
lifecycle
SandboxLifecycle
Sandbox lifecycle settings (onTimeout, autoResume).
apiKey
string
API key override for this call.
domain
string
Domain override for this call.
apiUrl
string
Full URL override for this call.
requestTimeout
number
Per-request HTTP timeout in milliseconds.

Quick example

import { Sandbox } from '@declaw/sdk';

const sbx = await Sandbox.create({
  apiKey: 'your-api-key',
  domain: '104.198.24.180:8080',
});

try {
  const result = await sbx.commands.run("echo 'hello from Declaw'");
  console.log(result.stdout);
} finally {
  await sbx.kill();
}

Using await using (TypeScript 5.2+)

import { Sandbox } from '@declaw/sdk';

await using sbx = await Sandbox.create({
  apiKey: 'your-api-key',
  domain: '104.198.24.180:8080',
});

const result = await sbx.commands.run("node --version");
console.log(result.stdout);
// sbx.close() is called automatically at block exit
await using calls sbx.close() which releases the HTTP client but does not kill the sandbox. Call await sbx.kill() explicitly to destroy the sandbox.

What’s exported

import {
  // Connection
  ConnectionConfig,
  // Sandbox
  Sandbox,
  // Templates
  Template,
  TemplateBase,
  // Security
  createSecurityPolicy,
  createPIIConfig,
  PIIType,
  RedactionAction,
  createInjectionDefenseConfig,
  InjectionSensitivity,
  InjectionAction,
  createNetworkPolicy,
  createTransformationRule,
  TransformDirection,
  createAuditConfig,
  createEnvSecurityConfig,
  ALL_TRAFFIC,
  // Errors
  SandboxError,
  TimeoutError,
  NotFoundError,
  AuthenticationError,
  CommandExitError,
} from '@declaw/sdk';