# JavaScript and TypeScript: choosing a path

There are four ways to use kosa8 from a Node program. Two are npm packages built for it, and two are standard protocols kosa8 speaks. They all reach the same daemon on your machine, so you can mix them. This page explains what each one is for and helps you pick.

Both npm packages can also run sandboxes on kosa8 Cloud instead of your machine: `@kosa8/sdk` ships `Kosa8Cloud`, and `@kosa8/ai-sdk-sandbox` ships `createKosa8CloudSandboxSession`. They need a `KOSA8_API_KEY` from [app.kosa8.com](https://app.kosa8.com) and no daemon. See the [Quickstart](https://docs.kosa8.com/guides/js-quickstart/#cloud) and the [API reference](https://docs.kosa8.com/guides/js-api/#cloud).

**How these pages were tested**

Every code block in this section was first run against a real kosa8 v0.9.10 daemon on an Apple silicon Mac, with the published packages `@kosa8/sdk@0.1.0` and `@kosa8/ai-sdk-sandbox@0.1.0` on Node.js 25.9.0. The current releases are kosa8 0.23.0, `@kosa8/sdk` 0.7.0 and `@kosa8/ai-sdk-sandbox` 0.2.1; install those. The output under each block is what that run printed, except the kosa8 Cloud examples, which were run against `https://api.kosa8.com` with `@kosa8/sdk` 0.5.3. The daemon ran in a separate state directory with `HOME=/tmp/k8d`, so paths in the output read `/tmp/k8d/…` where yours will show your home folder. Timings are from that run and will differ on your machine. A few things could not be run, such as a GitHub Actions job and a remote worker on another machine. Those are marked untested where they appear.

## The four paths

**@kosa8/sdk**A typed client for kosa8's native API, for Node 18 and later. It covers sandboxes, run and exec, network rules, the credential broker, checkpoints and rewind, fork, explore, snapshots and signed approvals. It has no runtime dependencies. Use it when your own code decides what runs: a backend that runs user code, a test harness, a CI step, or your own agent loop.

**@kosa8/ai-sdk-sandbox**A kosa8 sandbox for the Vercel AI SDK 7, for Node 22 and later. It implements the AI SDK's sandbox interfaces, so tools get an `experimental_sandbox` to read and write files and run commands in, and `HarnessAgent` can use it as its sandbox. Use it when the model decides what runs and you already build on the AI SDK.

**MCP**`kosa8 mcp serve` exposes 39 kosa8 tools over the Model Context Protocol, on stdio or HTTP. Any MCP client can use them: the AI SDK's MCP client, Mastra, LangChain.js, Claude Code and others. The model drives kosa8 directly. Use it when you want the agent to create and manage its own sandboxes, inside limits you set on the command line.

**Docker API**The daemon also serves the Docker Engine API on the same socket. dockerode, testcontainers-node and anything else built on them work after you set `DOCKER_HOST`. Containers run in kosa8's shared engine VM, not in sandboxes of their own. Use it when you already have Docker code and want it off Docker Desktop, unchanged.

## Decision table

| You want to… | @kosa8/sdk | AI SDK adapter | MCP | Docker API |
|---|---|---|---|---|
| Run code in a microVM with its own kernel | yes | yes | yes | no: the shared engine VM |
| Close the network, or allow named hosts only | yes, per sandbox | yes, `networkPolicy` | yes, per sandbox | no |
| Keep API keys out of the sandbox (broker) | yes | yes, `broker` | no | no |
| Checkpoint and rewind a running machine | yes | stop and resume only | yes | no |
| Fork, and try N approaches in parallel | yes | no | yes | no |
| Give an AI SDK agent file and shell tools | you write the tools | yes, built in | the model calls kosa8's tools | no |
| Let the model create its own sandboxes | no | no | yes | no |
| Reuse existing dockerode or Testcontainers code | no | no | no | yes |
| Bind-mount host folders | yes, `mounts` | yes, `mounts` | below `--allow-mount` | below `daemon start --allow-mount` |
| Signed approvals for risky actions | yes, `approval` option | yes, `approval` setting | yes, `approval` argument | yes (the gate is in front of every route) |
| Node version | 18+ | 22+ | any | any |

## How they fit together

> Diagram: Your Node program uses one of four clients: @kosa8/sdk, the AI SDK adapter built on it, an MCP client talking to kosa8 mcp serve, or dockerode. All four send HTTP to the kosa8d daemon over its unix socket. The daemon runs sandboxes, each a microVM, for the first three, and runs Docker API containers in its shared engine VM.

Every path enters at the same daemon, so every path is identified, gated by policy and written to the audit log the same way.

## Packages at a glance

| Package | Version | Node | Depends on | Formats |
|---|---|---|---|---|
| `@kosa8/sdk` | 0.7.0 | 18 or later | nothing at run time | ESM and CommonJS, with `.d.ts` |
| `@kosa8/ai-sdk-sandbox` | 0.2.1 | 22 or later | `@kosa8/sdk`, `@ai-sdk/harness`, `@ai-sdk/provider-utils` | ESM and CommonJS, with `.d.ts` |

Both are MIT-licensed. The licence covers the packages only, not kosa8 itself. Source: [github.com/kosa8ai/kosa8-js](https://github.com/kosa8ai/kosa8-js).

## What none of them can do yet

### Limits in kosa8 0.20.0 and `@kosa8/sdk` 0.5.3 (local client)

- **No SDK call changes a local sandbox's network rule.** `Kosa8Client` sets egress at creation only. The daemon itself accepts `PUT /kosa8/v1/sandboxes/{id}/egress` (see [Network and secrets](https://docs.kosa8.com/guides/js-network/)), which you can send with `kosa8.transport.json`.

- **No general port forwarding from sandboxes.** `createPreview` gives a signed, expiring link to a web server in a sandbox, but there is no call that maps a sandbox port onto the host. (The Docker API's `-p` works, on the shared engine.)

- **The file calls reach only the workspace.** `listFiles`, `readFile`, `writeFile` and the rest work on `/workspace`. The AI SDK adapter, and the exec helpers on the [Files](https://docs.kosa8.com/guides/js-files/) page for other paths, use `sh`, `cat` and `base64` inside the container, so the image needs them. Alpine, Debian and the Node images have them.

- **The Cloud client is a different API.** `Kosa8Cloud` (kosa8 Cloud) has its own methods: `box.exec`, `box.files`, `box.checkpoint` and `box.rewind`, `box.fork`, `box.snapshot`, previews, egress, functions, jobs and more. It has no `explore` and no host-folder mounts, and keeps credentials out with org secrets rather than the local broker. See [API reference](https://docs.kosa8.com/guides/js-api/#cloud).

- **No stdin for exec.** A command started with `exec` cannot read stdin. Use `startInteractive` and `writeStdin` for a process that needs input.

- **Checkpoints are built from snapshots on the client side.** The daemon has no checkpoint endpoint. The SDK keeps the list in the same file as the CLI, `~/.kosa8/checkpoints.json`, so both see the same checkpoints.

- **Remote workers are untested from the SDK.** The SDK accepts `KOSA8_HOST` and `KOSA8_TOKEN` like the CLI. It was tested over the unix socket and over loopback TCP on one machine, not against a worker on another machine.

## Start here

[`Install and prerequisites` kosa8, the daemon, Node, and a first health check.](https://docs.kosa8.com/guides/js-install/) [`Quickstart` Your first sandbox from TypeScript in five steps, each with its output.](https://docs.kosa8.com/guides/js-quickstart/) [`Vercel AI SDK adapter` Give an AI SDK agent a sealed machine for files and commands.](https://docs.kosa8.com/guides/js-ai-sdk/) [`Recipes` Complete, tested programs for common jobs.](https://docs.kosa8.com/guides/js-recipes/)

---
Source: https://docs.kosa8.com/guides/js-overview/
