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 and no daemon. See the
Quickstart and the
API reference.
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#
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.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_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#
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.
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.
Kosa8Clientsets egress at creation only. The daemon itself acceptsPUT /kosa8/v1/sandboxes/{id}/egress(see Network and secrets), which you can send withkosa8.transport.json. - No general port forwarding from sandboxes.
createPreviewgives 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-pworks, on the shared engine.) - The file calls reach only the workspace.
listFiles,readFile,writeFileand the rest work on/workspace. The AI SDK adapter, and the exec helpers on the Files page for other paths, usesh,catandbase64inside 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.checkpointandbox.rewind,box.fork,box.snapshot, previews, egress, functions, jobs and more. It has noexploreand no host-folder mounts, and keeps credentials out with org secrets rather than the local broker. See API reference. - No stdin for exec. A command started with
execcannot read stdin. UsestartInteractiveandwriteStdinfor 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_HOSTandKOSA8_TOKENlike 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.
Quickstart
Your first sandbox from TypeScript in five steps, each with its output.
Vercel AI SDK adapter
Give an AI SDK agent a sealed machine for files and commands.
Recipes
Complete, tested programs for common jobs.
Something wrong or missing? Write to contact@kosa8.com.