Skip to main content
Install the npm package:
Import BoxApi, configure auth, and call methods like box.create, box.prompt, and box.events.

Configure

For TypeScript projects, use modern Node resolution and DOM fetch types:
Node 18+ provides fetch. Older runtimes need a fetch polyfill. For ESM examples, set "type": "module" in package.json; CommonJS projects can use the require example below.

Create, prompt, and clean up

Use ttlSeconds when creating a Box. Set a friendly name afterward with box.update.

Per-box environment variables

Pass env to inject variables into a single Box, on top of your account-level secrets (per-box values win on name conflicts). At most 100 variables, 64KB total.
Forked Boxes inherit the source Box’s env unless the fork supplies its own.

No-env boxes

When you hand a Box to your own end users, create it with noEnv: true so none of your account secrets reach it. Model keys, GitHub token, dashboard environment variables, SSH identity, and secret files are all withheld. SSH, desktop, snapshots, public URLs, and forks still work. A fork of a no-env Box is always no-env and cannot be downgraded.

CommonJS

Methods

All methods are called on BoxApi. Request bodies are plain objects typed by the exported model interfaces.

Browse a stopped Box’s filesystem

Snapshot reads never touch the machine, so they work while the Box is archived:

Waiters and helpers

The package exports first-class waiters and deterministic file/command helper functions:
Use waitForPrompt/waitForPromptDone instead of inferring completion from box.state plus event polling. Use streamPrompt or streamEvents when you need incremental response/tool-call events as work runs.

Streaming responses and tool calls

The SDK now exports streamEvents and streamPrompt for response streaming. They use the Box v1 events cursor API under the hood, so no separate SSE or WebSocket endpoint is required. response events carry text in event.data.content; streaming partials set event.data.isStreaming; tool-call events are response events with event.data.tools.
For a dashboard-style feed not tied to one prompt, use streamEvents(box, boxId, { type: "prompt,response,git_checkpoint" }) and stop it with an AbortController.

Operation request types

These exported interfaces wrap method parameters for BoxApi methods.

Model types

TypeScript models use camelCase fields.

Errors

Non-2xx responses reject with a ResponseError. Read the status and parse the JSON body for the structured Box error envelope. Redact API keys, Box secrets, SSH keys, and desktop URLs.