CrowNest
TypeScript SDK

TypeScript SDK

Install the @crownest/sdk package, construct a client, and navigate the resource clients.

The @crownest/sdk package is the official TypeScript client for CrowNest. It wraps the REST API with typed resource clients for sandboxes, commands, files, artifacts, previews, and projects, and returns a convenient SandboxHandle that binds helpers to a specific sandbox.

Install

Add the package to your project with your package manager of choice.

Terminal
pnpm add @crownest/sdk
# or
npm install @crownest/sdk
# or
yarn add @crownest/sdk

Create a client

Call createCrowNestClient to construct a client. All options are optional.

import { createCrowNestClient } from "@crownest/sdk";

const client = createCrowNestClient({
  apiKey: "cn_live_...", // falls back to env CROWNEST_API_KEY
  baseUrl: "https://api.crownest.dev", // default
});
OptionTypeDefaultDescription
apiKeystringCROWNEST_API_KEY env varOrg-scoped API key. The client throws if neither the option nor the env var is set.
baseUrlstringhttps://api.crownest.devAPI base URL.
fetchtypeof fetchglobal fetchCustom fetch implementation.

Create API keys in the dashboard; the raw key value is shown once at creation.

SandboxHandle

client.sandboxes.create() and client.sandboxes.get() return a SandboxHandle: the full Sandbox object (id, status, expiresAt, metadata, and so on) plus helpers bound to that sandbox, so you don't pass the sandbox ID on every call.

const sandbox = await client.sandboxes.create({ template: "python" });

const result = await sandbox.commands.run("python -c 'print(40 + 2)'");
console.log(result.exitCode, result.stdout);

await sandbox.files.write("notes.txt", "hello from crownest");
const artifact = await sandbox.artifacts.create({ path: "notes.txt" });

await sandbox.kill();

The handle exposes:

  • sandbox.commands.run, sandbox.commands.start, sandbox.commands.cancel
  • sandbox.files.read, write, delete, list, stat, mkdir, move, downloadUrl
  • sandbox.artifacts.create, sandbox.artifacts.list
  • sandbox.previews.create, sandbox.previews.list
  • sandbox.kill() — destroys the sandbox and returns an updated handle

For operations that target a resource by ID rather than a sandbox (for example commands.get or artifacts.download), use the top-level clients on client.

Projects

List the projects your API key can access.

const projects = await client.projects.list();
// [{ id: "prj_...", orgId, name, createdAt }, ...]

list() returns Promise<readonly Project[]>.

Exported types

The package exports CrowNestClientOptions, RunCommandOptions, SandboxHandle, and the CrowNestApiError class, plus the resource types (Sandbox, Command, Artifact, Preview, Project, and friends) from the contracts package.

Resource clients

Each resource client has its own reference page:

  • Sandboxesclient.sandboxes: create, get, list, kill.
  • Commandsclient.commands: run, start, get, cancel, logs, streamLogs.
  • Filesclient.files: read, write, delete, list, stat, mkdir, move, downloadUrl.
  • Artifactsclient.artifacts: create, list, get, download, downloadUrl, delete.
  • Previewsclient.previews: create, list, get, revoke.
  • ErrorsCrowNestApiError, error codes, and retry guidance.

Next steps

On this page