agent-neckbeard 1.1.27 → 1.1.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/AGENT.md ADDED
@@ -0,0 +1,205 @@
1
+ # Agents from Prebuilt Images
2
+
3
+ An agent runs a Pi session from a container image you build ahead of time, usually in CI. The image holds everything the agent needs: OS packages, Python and npm dependencies, skills, and the agent itself. Starting a sandbox installs and uploads nothing, so a cold start is the provider's sandbox start plus the agent process start.
4
+
5
+ This replaces `LegacyBundledAgent`, which bundles the agent's code on the host and uploads it, its dependencies, and its local directories at every deploy. That class still works and is deprecated.
6
+
7
+ ## Defining an agent
8
+
9
+ `defineAgent()` describes an agent once, in one module: its image, its sandbox, and its Pi session. Your process imports it to start sandboxes and run turns; `neckbeard build` bundles the same module as the image's entry point, which serves the session.
10
+
11
+ ```ts
12
+ // agent.ts
13
+ import { defineAgent } from "agent-neckbeard";
14
+ import type { JsonAgentSessionEvent } from "@earendil-works/pi-coding-agent";
15
+
16
+ export const myAgent = defineAgent<JsonAgentSessionEvent>({
17
+ name: "my-agent", // the image is ghcr.io/acme/my-agent:<tag>
18
+ registry: "ghcr.io/acme",
19
+ sandbox: { provider: "modal", cpu: 2, memoryMiB: 4096, regions: ["us-east"], registrySecret: "ghcr" },
20
+ envs: () => ({ OPENAI_API_KEY: process.env.OPENAI_API_KEY }),
21
+ maxTurnDurationMs: 2 * 60 * 60 * 1000, // optional: ends a turn that runs longer as failed
22
+ pi: {
23
+ model: "openai/gpt-6.1-sol",
24
+ thinkingLevel: "high",
25
+ tools: ["read", "bash", "grep", "ls"],
26
+ systemPrompt: "You are ...",
27
+ cwd: "workspace",
28
+ },
29
+ });
30
+ ```
31
+
32
+ `sandbox` and `envs` may be functions, read the first time the host needs them, so the image, which never calls them, needs none of the host's configuration. Pass Pi's `JsonAgentSessionEvent` to type the events; neckbeard's own declarations don't reference Pi's, so a package that only runs turns needn't install Pi.
33
+
34
+ `pi` creates the session in the sandbox, which needs Pi's Node.js 22.19 or later (`PiSessionConfig` in [`src/define.ts`](../src/define.ts)):
35
+
36
+ - `model` as `provider/model`, with `thinkingLevel` and the built-in `tools` to enable. The model's credential comes from the sandbox's environment, such as `OPENAI_API_KEY`.
37
+ - `systemPrompt` replaces Pi's. Pi's agent directory is `~/agent/.pi`, and its skills are the image's `/app/.agents/skills` (`SKILLS_DIR`) only: no extensions, prompt templates, or context files are loaded from the sandbox.
38
+ - `cwd`, relative to the sandbox user's home unless absolute (default `workspace`), is created before the session and exported as `NECKBEARD_CWD`, so the agent's scripts can find it.
39
+ - `persist` keeps the conversation in `~/agent/.pi/sessions/<sessionId>.jsonl`, for the `sessionId` passed to `start()`, so a restarted runtime, or a sandbox restored from a copy of that file, continues it. `sessionFilePath(homeDir, sessionId)` gives the path for copying it out and back. Otherwise the conversation lives in memory as long as the sandbox.
40
+
41
+ For a session that config can't express, pass `createSession` instead of `pi`, returning anything with Pi's `subscribe`, `prompt`, and `abort`, optionally `steer` and `clearQueue`, both or neither, for steering, and optionally `afterTurn()`, which runs once each turn's outcome is known, before its `end` record and outside its deadline, as to send traces; an abort that arrives meanwhile changes nothing. Keep it bounded, since it delays the `end` record. A definition needs exactly one of them.
42
+
43
+ ### Tracing
44
+
45
+ A `pi` agent traces its turns in [Braintrust](https://www.braintrust.dev) when its sandbox has `BRAINTRUST_API_KEY` and `BRAINTRUST_PROJECT_NAME`. Pass them in `envs`, and add `braintrust` `>=3.44.0 <4.0.0`, an optional peer dependency, to the agent's package's `dependencies` (not `devDependencies`), so `neckbeard build` installs it in the image, shared with any imports of it in the agent's own code; the build fails on a version outside that range, which can't trace Pi 1.x:
46
+
47
+ ```ts
48
+ envs: () => ({
49
+ OPENAI_API_KEY: process.env.OPENAI_API_KEY,
50
+ BRAINTRUST_API_KEY: process.env.BRAINTRUST_API_KEY,
51
+ BRAINTRUST_PROJECT_NAME: "my-agent",
52
+ }),
53
+ ```
54
+
55
+ Each turn is a trace of Pi's prompt, its model calls, and its tool calls, sent once its outcome is known: before its `end` record, so a sandbox deleted right after a turn loses nothing, and outside `maxTurnDurationMs`, so sending it can't fail the turn. Tracing never fails a turn: a trace that can't be sent within 10 seconds, or a Braintrust that can't start, is reported with `console.warn` and the agent runs on. The key turns tracing on: without it, tracing is off, so an agent can name its project and run untraced wherever no key is configured, as in local development. A key without a project name is a mistake: the first `start()` warns on the host, the sandbox warns in its own log, and the agent runs untraced.
56
+
57
+ A sandbox with a network allowlist must allow `www.braintrust.dev`, where Braintrust logs in, and the organization's API host, by default `api.braintrust.dev`.
58
+
59
+ ### Image names
60
+
61
+ A host runs `<registry>/<name>:<tag>`, where the tag is the first of these set: `NECKBEARD_IMAGE_TAG`, then the commit its platform deployed, from the variables [Sentry reads](https://github.com/getsentry/sentry-javascript/blob/develop/packages/core/src/utils/commitEnv.ts) for the same purpose (`GITHUB_SHA`, `CI_COMMIT_SHA`, `RENDER_GIT_COMMIT`, `VERCEL_GIT_COMMIT_SHA`, `RAILWAY_GIT_COMMIT_SHA`, `HEROKU_SLUG_COMMIT` and others; `resolveImageTag()`). So CI tags each image with its commit, and a deployed host runs the image of its own commit, without configuration; set `NECKBEARD_IMAGE_TAG` where no commit is known, as in local development: `master` follows each push on Daytona and E2B, but Modal keeps a tag's first contents, so a Modal agent needs a commit's tag. The tag is the commit rather than a hash of the image's contents because a host doesn't have the build context to hash. `image` instead of `registry` names a full image reference, and `imageRef(tag?)` returns the image a host would run. A definition without either fails, and a host that can't find a tag fails when it first starts a sandbox.
62
+
63
+ ## Building and pushing the image
64
+
65
+ From the agent's package, after logging in to the registry:
66
+
67
+ ```sh
68
+ npx neckbeard push agent.ts [--export <name>] [--tag <tag>]... [--cache] [--dry-run]
69
+ ```
70
+
71
+ `push` writes the image's build context, as `neckbeard build` does, to a temporary directory it removes afterwards, so the package needn't ignore it, and builds it for `linux/amd64`, which every provider runs, with the package's `sandbox/Dockerfile` (`build.dockerfile`) and `docker build`, tagged `<registry>/<name>:<tag>` for each `--tag` (default: `resolveImageTag()`, so `GITHUB_SHA` in a GitHub workflow). It then pushes each tag, and readies each for its provider: on Daytona it builds the tag's snapshot, on E2B its template, again even when one exists, since a tag such as `master` may now name new contents, and deletes older ones, keeping three in all and never one this push built (`prepare({ refresh: true })` and `gc({ keep: 3, alsoKeep })`), so no sandbox start waits on a build. Modal pulls the image itself, and [keeps a tag's contents once pulled](https://modal.com/docs/guide/sandboxes#separating-image-builds-from-sandbox-creation), so a reused tag such as `master` can't be refreshed there: a Modal host should run an immutable tag, as a deployed host running its commit does, and `push` says so for each later tag of a Modal agent. That needs the provider's credentials, such as `DAYTONA_API_KEY`, and whatever the definition's `sandbox` function reads. `--cache` builds with `docker buildx`, reusing and updating layers cached in the registry under the image's `buildcache` tag. `--dry-run` builds without pushing or preparing, as for a pull request. `--export` picks the agent when the module exports several; by default it is the default export or the module's only agent. `pushAgent()` from `agent-neckbeard/build` does the same. A workflow:
72
+
73
+ ```yaml
74
+ - uses: docker/setup-buildx-action@v3
75
+ - uses: docker/login-action@v3
76
+ with: { registry: ghcr.io, username: "${{ github.actor }}", password: "${{ secrets.GITHUB_TOKEN }}" }
77
+ - run: npx neckbeard push agent.ts --tag ${{ github.sha }} --tag latest --cache ${{ github.event_name == 'pull_request' && '--dry-run' || '' }}
78
+ working-directory: packages/my-agent
79
+ env: { DAYTONA_API_KEY: "${{ secrets.DAYTONA_API_KEY }}" }
80
+ ```
81
+
82
+ `neckbeard build agent.ts [--export <name>] [--out dist-sandbox]` writes only the build context, for inspecting it. It replaces `dist-sandbox/`, or `--out`, with three things. It refuses an output directory that holds the package or its module, or that is not empty and was not written by an earlier build.
83
+
84
+ - `agent.mjs`: the module, bundled with an entry point that calls the agent's `serve()`. Pi's packages (`@earendil-works/*`), Braintrust for a `pi` agent whose package depends on it, the host-only provider SDKs, and each package in the definition's `build.external` stay out of the bundle, for ones that load native modules or wasm or otherwise must be installed. The build loads the module on the host to read its definition, so its top level must not need the image.
85
+ - `package.json`: those packages, each pinned to the version its importer resolves, as Node will in the image. The build fails when the bundle imports one package at two versions.
86
+ - `.agents/skills/`: the package's own skills from `skills/`, plus the third-party skills its `skills-lock.json` pins. It restores those with the [skills CLI](https://www.npmjs.com/package/skills) (`skills@1.8.1`, run as `experimental_install --frozen-lockfile`), which fetches each at its locked commit and fails unless its files match the lock's hash. That CLI is an optional dependency that needs Node.js 22.20 or later, so a package with a `skills-lock.json` must be built on such a Node; the rest of the package keeps its wider Node range.
87
+
88
+ Commit `skills/` and `skills-lock.json`, never the third-party skills' files. To add or update one, run `npx skills@1.8.1 add <owner>/<repo>#<full commit SHA> --skill <name> --copy` in the package, review what it fetched, commit the lock, and delete the `.agents` it wrote. The build fails when a lock entry's `ref` is not a full commit SHA, since the lock records the ref as typed; when a skill is in both `skills/` and the lock; when a skill directory has no `SKILL.md`; or when a skill holds a symbolic link that is absolute or points outside the skill, since it would not resolve in the image. Links inside a skill are copied as they are.
89
+
90
+ The build fetches over the network, but `docker build` then sees only local files. A Dockerfile puts the bundle in `/app` with its unbundled dependencies and skills:
91
+
92
+ ```dockerfile
93
+ FROM python:3.14-slim-trixie
94
+ COPY --from=node:22-trixie-slim /usr/local/bin/node /usr/local/bin/node
95
+ COPY --from=node:22-trixie-slim /usr/local/lib/node_modules /usr/local/lib/node_modules
96
+ RUN ln -s ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
97
+ RUN apt-get update && apt-get install -y --no-install-recommends bash ca-certificates curl \
98
+ && rm -rf /var/lib/apt/lists/*
99
+ WORKDIR /app
100
+ COPY package.json ./
101
+ RUN npm install --omit=dev
102
+ COPY agent.mjs ./
103
+ COPY .agents /app/.agents
104
+ CMD ["node", "/app/agent.mjs"]
105
+ ```
106
+
107
+ The runtime listens on `NECKBEARD_PORT`, which the host sets, or 8080, and sends Pi's events in the JSON form Pi's JSON and RPC modes write: a `message_update` carries only its delta, not the cumulative message. The image needs Bash for file and command access through `SandboxClient`. Never bake secrets into it: pass them as `envs`, or as turn `env`.
108
+
109
+ ## The host
110
+
111
+ ```ts
112
+ import { getPiTurnResult } from "agent-neckbeard";
113
+ import { myAgent } from "./agent";
114
+
115
+ const sandboxId = await myAgent.start({ sessionId });
116
+ for await (const record of myAgent.prompt(sandboxId, {
117
+ turnId: runId,
118
+ message: "Summarize the data room.",
119
+ env: { API_TOKEN: shortLivedToken },
120
+ })) {
121
+ if (record.type === "event") store(record.seq, record.event);
122
+ else console.log(record.outcome, record.error);
123
+ }
124
+ await myAgent.kill(sandboxId);
125
+ ```
126
+
127
+ Every method takes the sandbox ID, so a host process that restarts, or another one, can drive a sandbox the first one started.
128
+
129
+ | Method | Does |
130
+ |---|---|
131
+ | `start({ envs, sessionId, signal })` | Prepares the image for the provider if needed, creates a sandbox whose main process is the image's runtime, waits until it answers, returns the sandbox ID. `sessionId` is the sandbox's `NECKBEARD_SESSION_ID`, which names a persisted session's file. A start that fails or is cancelled deletes its sandbox; if that fails too, it throws `DeploymentError` with the `sandboxId` to `kill()` |
132
+ | `prompt(sandboxId, { turnId, message, env }, { after, signal })` | Starts a turn and yields its records until its `end` record. A `turnId` the runtime already has resumes that turn instead of running it again |
133
+ | `run(sandboxId, turn, { onRecord, signal })` | Runs a turn to its end, passing each record to `onRecord`, and returns the last assistant message's text; throws `ExecutionError` when the turn doesn't complete. Calling it again with the same `turnId` resumes the turn and replays its records from the start, so store them keyed by `seq` |
134
+ | `events(sandboxId, turnId, { after, signal })` | Resumes a turn's records after `after`. Throws `TurnLostError` when the runtime no longer has the turn |
135
+ | `abort(sandboxId, turnId)` | Stops the turn; its stream ends with an `aborted` record |
136
+ | `steer(sandboxId, turnId, { steerId, message })` | Queues a message for the running turn, which Pi takes after its current tool calls and before its next model call, where it shows in the stream as a user message. Returns `true` once the session has queued it, and `false` when the turn can no longer take it, so the caller can send the message as a turn of its own. Throws when queueing failed; calling again with the same `steerId` is safe. See [Steering](#steering) |
137
+ | `health`, `waitForIdle` | Whether a turn is running |
138
+ | `sandbox(sandboxId)` | A `SandboxClient` for files and commands, for staging inputs or reading results |
139
+ | `kill(sandboxId)` | Deletes the sandbox without starting it. One that is gone counts as deleted; any other failure throws, so cleanup can be retried, since a Daytona sandbox without `autoDeleteInterval` never expires |
140
+ | `prepare({ refresh })` | Creates the Daytona snapshot or E2B template if missing, or replaces one an earlier attempt left failed, or with `refresh` builds it again, within `prepareTimeoutMs` (30 minutes) and the caller's `signal`; does nothing on Modal |
141
+ | `gc({ keep, alsoKeep })` | Deletes this agent's older Daytona snapshots or E2B templates (exactly `nb-<name>-<hash>`, so not another agent's whose name starts with this one's), keeping the newest `keep`, and never the current one or those named in `alsoKeep` |
142
+
143
+ The first call builds the agent's `Agent` for the image `imageRef()` names; `forImage(image)` returns one for another image. `new Agent({ name, image, sandbox, envs })` takes the same options for an image built some other way, and `serve({ createSession })` from `agent-neckbeard/serve` serves a session from an entry point you write yourself.
144
+
145
+ `getPiTurnResult(records)` reads how a turn ended: completed with its last assistant message's text when the records include the `end` record, the turn ended normally, and the model stopped on its own; otherwise an error, including for records that stop before the `end` record.
146
+
147
+ `signal` stops reading a stream, never the turn: a host that stops or restarts leaves the turn running, and the next `prompt` or `events` call resumes it. Use `abort()` to stop a turn. A stream that drops reconnects on its own from the last record, and fails after `reconnectTimeoutMs` (two minutes) without a healthy connection. A connection is healthy while bytes arrive: records, the comment the runtime sends as a stream opens, or its heartbeat every 15 seconds. A connection that sends nothing for that long is abandoned, including one the server accepts and never answers, so keep `reconnectTimeoutMs` above 15 seconds. An `Agent` prepares once and reuses the result, until a start fails to create its sandbox, as when a newer release's `gc()` deleted its snapshot; the next start then prepares again. `start()` and `waitForIdle()` bound each health check by their own deadlines, and a malformed `/health` body is an error, never an idle runtime. A whole record that is invalid fails the stream with `ExecutionError` rather than being retried, while a record cut off by a dropped connection is read again after reconnecting.
148
+
149
+ ## Providers
150
+
151
+ | Provider | How the image becomes a sandbox | Private images |
152
+ |---|---|---|
153
+ | Modal | Pulled directly; the runtime is the sandbox's command | `registrySecret` names a Modal Secret with `REGISTRY_USERNAME` and `REGISTRY_PASSWORD` |
154
+ | Daytona | `prepare()` creates a snapshot named `nb-<name>-<hash>` with the runtime as its entrypoint | Add the registry once in the Daytona dashboard |
155
+ | E2B | `prepare()` builds a template named `nb-<name>-<hash>`; `start()` launches the runtime as a background command, because a template's start command runs once at build time without each sandbox's environment | `registry: { username, password }`, used only when building the template |
156
+
157
+ The hash covers the image reference, the command (Daytona), and the resources, so equal inputs share a snapshot or template and `prepare()` is a lookup. `neckbeard push` runs `prepare()` after pushing the image so no sandbox waits on a build; in our live tests a first build took 20 to 45 seconds, and a sandbox start after it about 2.5 seconds. It then runs `gc()` to delete older ones. Docker is not supported by `Agent` yet.
158
+
159
+ ## Turn protocol
160
+
161
+ `serve()` speaks protocol version 3 over HTTP, behind each provider's endpoint auth (`TURN_PROTOCOL_VERSION`; types in `src/turn-protocol.ts`).
162
+
163
+ - `GET /health` returns `{ ok, protocolVersion, busy, turnId }`. `busy` stays true until the turn's prompt has returned and its `env` is restored, which can be after its `end` record, as when an event fails to convert and the prompt is still stopping. `start()` rejects a runtime with another protocol version.
164
+ - `POST /turns` with `{ turnId, message, env? }` starts a turn and returns 202. A known `turnId`, the current or previous turn, returns 200 without starting anything; another turn while one is busy returns 409. `env` is set in `process.env` for the turn and restored after it.
165
+ - `GET /turns/:turnId/events?after=<seq>` opens with an SSE comment, streams the turn's records after `seq`, then live records with a heartbeat comment every 15 seconds, and closes after the `end` record. A reader already past the end of an ended turn gets the `end` record again, so it can tell the turn ended from a dropped stream. Unknown turns return 404.
166
+ - `POST /turns/:turnId/abort` returns 202 and aborts the session's prompt. Pi waits for a running tool before its prompt returns, so a turn that is aborted, or exceeds `maxTurnDurationMs` (which counts from the turn's start, creating the session included), and hasn't stopped within `serve()`'s `abortGraceMs` (10 seconds) gets its end record anyway. `busy` stays true until the prompt does return.
167
+ - `POST /turns/:turnId/steer` with `{ steerId, message }` hands the session a message for the turn that is running. See [Steering](#steering) for what each answer promises.
168
+
169
+ A record is `{ seq, type: "event", event }` or `{ seq, type: "end", outcome: "completed" | "aborted" | "failed", error?, undeliveredSteerIds? }`. `seq` starts at 0 for each turn and increases by one, and the runtime serializes each record when it is written, so a replay of a `seq` sends exactly what streamed live, and a host can store records keyed by `seq` and ignore repeats. The runtime keeps the current and previous turns in memory. A runtime that restarts, or a replaced sandbox, loses them, and a resume then fails with `TurnLostError`.
170
+
171
+ ### Steering
172
+
173
+ A steer is a message for one turn. The runtime gives each steer exactly one outcome, by its `steerId`, and never lets one reach a later turn.
174
+
175
+ **What the answer means.** The request is answered once the session has finished queueing the message, which may take a while when Pi runs input hooks first.
176
+
177
+ | Status | Meaning | What the caller does |
178
+ |---|---|---|
179
+ | 202 | The session queued the message for this turn. It is not delivered yet. With `handled: true`, an input hook took the message instead of queueing it, and nothing more happens to it | Wait for the turn's records |
180
+ | 200 | A repeat of a steer this turn already has. It got the same outcome as the first request, which this one waited for | The same |
181
+ | 409 | The turn is not taking steers: it has ended, is stopping, its prompt has returned, or it stopped taking them while this one was being queued and the runtime took the message back out of the queue. The message will not be delivered | Send it as a turn of its own |
182
+ | 500 | Queueing threw, as when Pi rejects an extension command. The steer is forgotten | Retry with the same `steerId`, or give up |
183
+ | 501 | The session has no `steer()`, or no `clearQueue()` to take an untaken steer back with | |
184
+
185
+ **What happens to a queued steer.** One of two things, and the turn's records say which. Either Pi delivers it, and it appears in the stream as a user `message_start` event; Pi does that after its current tool calls, or as a further run of the same prompt when the model had already answered. Or the turn ends first and its `end` record names it in `undeliveredSteerIds`; the runtime has taken it back out of the session's queue, so nothing will act on it, and the caller decides what becomes of it. A steer is never both, and never neither.
186
+
187
+ **Order.** Steers are queued one at a time, in the order their requests arrived, starting once the session exists. An abort or the turn's deadline closes the turn to new steers at once, takes back the ones still queued before asking the session to stop, and never starts a prompt that had not started. A turn that ends any other way while its prompt is still stopping, as when an event fails to convert, takes them back the same way. The `end` record is written only after every steer being queued has settled, or after `abortGraceMs` if one is stuck in a hook, which for a turn that was told to stop is the same grace period its prompt gets, not a second one; the runtime stays `busy`, with the turn's `env` still set, until that one settles, and drops it then. If the session's `clearQueue()` throws, the runtime can't tell what is left, so it names every steer still queued as undelivered and creates a new session for the next turn.
188
+
189
+ **Retries.** `steerId` is the idempotency key, for as long as the runtime keeps the turn (the current and previous ones). A repeat never queues the message twice: while the first request is in flight it waits for it, and afterwards it reports the steer's outcome, 200 for one that was delivered and 409 for one that was not.
190
+
191
+ Where this follows others and where it does not:
192
+
193
+ - The answer means queued, not delivered, and delivery is a separate signal in the stream, as in Pi's own RPC mode (`queue_update`), Codex (`turn/steer`), Trigger.dev and OpenCode. Holding the request until delivery, as the Agent Client Protocol's v2 draft and the Vercel AI SDK's `steer()` do, would keep a request open through a sandbox tunnel for as long as a tool runs.
194
+ - Every accepted steer is settled exactly once and the leftovers are handed back when the turn ends, as pi-durable settles each submission `done` or `unanswered` and the AI SDK resolves each steer delivered or not. Pi itself leaves a leftover in its queue, where the next prompt picks it up.
195
+ - A steer that is too late is refused rather than promoted, as Codex refuses one whose `expectedTurnId` is not the active turn. Most products make it the next turn themselves; here the caller owns the queue of turns, so the caller does that.
196
+ - An abort takes back the queued steers first, which is what Pi documents for its own hosts ("send `clear_queue` before `abort`") and what its terminal UI does. Pi's `abort()` alone leaves them: one may be written into the stopped turn unanswered, or wait for the next prompt, depending on when the abort lands.
197
+ - A repeat attaches to the original and shares its outcome, as a Temporal Update with a known ID does, rather than answering 409 while the first is in flight as Stripe's idempotency keys do, so a caller needs no retry loop.
198
+
199
+ Delivered steers are told from undelivered ones by position: Pi takes its queue oldest first and identifies messages only by their text, so the ones left are the last ones the session queued. The runtime is therefore only as exact as the session's own count of its queue. Pi keeps that count by text, so a steer with the same text as the turn's own message can drop out of it before Pi delivers the steer; if the turn is then stopped, that steer counts as delivered. A custom `toWireEvent` that throws on the queue update Pi emits while it queues a steer has the same effect on that steer.
200
+
201
+ ## Limits
202
+
203
+ - The session runs in the runtime process: if the agent crashes the process, the turn is lost and the provider's sandbox usually ends with it.
204
+ - One turn runs at a time per sandbox.
205
+ - `Agent` supports Pi-style sessions only. Other runtimes would get their own class.
@@ -0,0 +1,56 @@
1
+ # Daytona Provider
2
+
3
+ Daytona runs `Agent`, `SandboxClient`, and the deprecated `LegacyBundledAgent`. Set `DAYTONA_API_KEY` on the host, or pass `apiKey` in the sandbox config.
4
+
5
+ ## Images and snapshots
6
+
7
+ Daytona starts sandboxes from snapshots. `Agent.prepare()` turns the agent's registry image into a snapshot named `nb-<name>-<hash>`, where the hash covers the image, the start command, and `resources` (`{ cpu, memory, disk }`, vCPUs and GiB), and waits until it can start sandboxes. Run it from CI after pushing the image; `start()` otherwise creates a missing snapshot itself, which takes minutes. `gc({ keep })` deletes this agent's older snapshots. To pull a private image, add its registry once in the Daytona dashboard. For `SandboxClient` and `LegacyBundledAgent`, `sandbox.template` names an existing snapshot, such as `daytona-small`.
8
+
9
+ ## Network policy
10
+
11
+ Daytona sandboxes can also receive network policy options supported by the Daytona SDK. Use `domainAllowList` for domains and wildcard domains, or `networkAllowList` for comma-separated CIDR ranges:
12
+
13
+ ```typescript
14
+ new Agent({
15
+ name: "my-agent",
16
+ image: "ghcr.io/acme/my-agent:<commit>",
17
+ sandbox: { provider: "daytona", domainAllowList: "api.openai.com,*.example.com" },
18
+ });
19
+ ```
20
+
21
+ Set `networkBlockAll: true` only when you want to block all outbound network access. Daytona rejects `networkBlockAll: true` combined with non-empty allow lists.
22
+
23
+ Modal sandboxes accept the same three options in the same shape. Modal's domain allow list only passes HTTPS, so see [Modal network policy](MODAL.md#network-policy).
24
+
25
+ ## Lifecycle
26
+
27
+ `autoStopInterval` and `autoDeleteInterval` set the sandbox's Daytona lifecycle, in whole minutes, when the sandbox is created; reconnecting to an existing sandbox does not change them. Daytona stops a sandbox after `autoStopInterval` minutes without activity (`0` disables auto-stop; omitting it keeps Daytona's default, 15 minutes for standard sandbox classes) and deletes it `autoDeleteInterval` minutes after it stops (`0` deletes it immediately; `-1`, the default, never auto-deletes it). `new Agent()` rejects values that are not whole minutes.
28
+
29
+ ## SandboxClient
30
+
31
+ Use `SandboxClient` when host code needs provider-neutral filesystem or command access without running an agent invocation, such as staging documents into a sandbox before an agent runs or pulling artifacts out afterward:
32
+
33
+ ```typescript
34
+ import { SandboxClient } from "agent-neckbeard";
35
+
36
+ const sandbox = await SandboxClient.create({
37
+ provider: "daytona",
38
+ template: "daytona-small",
39
+ domainAllowList: "*.example.com",
40
+ autoDeleteInterval: 30,
41
+ });
42
+
43
+ const documentsDir = `${sandbox.paths.homeDir}/documents`;
44
+ await sandbox.makeDir(documentsDir);
45
+ await sandbox.writeFile(`${documentsDir}/input.txt`, "hello");
46
+ const result = await sandbox.runCommand("ls documents", {
47
+ cwd: sandbox.paths.homeDir,
48
+ timeoutMs: 60_000,
49
+ });
50
+ const bytes = await sandbox.readFileBytes(`${documentsDir}/input.txt`);
51
+ await sandbox.kill();
52
+ ```
53
+
54
+ ## Paths and HTTP
55
+
56
+ Daytona resolves the sandbox user's home directory at runtime (`/home/daytona` on default snapshots), so use `sandbox.paths.homeDir` rather than a fixed path. Neckbeard reaches a sandbox's server through a Daytona preview link and sends its preview token as the `DAYTONA_SANDBOX_AUTH_KEY` query parameter; callers only store the sandbox ID.
package/docs/DOCKER.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Docker Provider
2
2
 
3
- The Docker provider runs the same agent runtime in a container on a local Docker daemon. It is supported by both `Agent` and `SandboxClient` and needs only the `docker` CLI on the host `PATH`; there is no SDK dependency and no credential.
3
+ The Docker provider runs the same agent runtime in a container on a local Docker daemon. It is supported by both `LegacyBundledAgent` and `SandboxClient` and needs only the `docker` CLI on the host `PATH`; there is no SDK dependency and no credential.
4
4
 
5
5
  **It is a development and evaluation provider, not an isolation boundary.** E2B, Daytona, and Modal place untrusted agent tool calls inside a provider-operated microVM or gVisor sandbox. A Docker container shares the host kernel and runs here as root. Use it to iterate locally, to run evals next to local services on a compose network, and in CI. Do not use it to contain untrusted input in production, and note that the primary serverless consumers (Vercel Functions, Trigger.dev) have no Docker daemon at all.
6
6
 
@@ -30,17 +30,17 @@ All settings except `provider` are optional:
30
30
 
31
31
  | Setting | Default | Meaning |
32
32
  | --- | --- | --- |
33
- | `template` | `node:22-bookworm` | Debian-compatible image. `Agent` requires Node.js and npm in it |
33
+ | `template` | `node:22-bookworm` | Debian-compatible image. `LegacyBundledAgent` requires Node.js and npm in it |
34
34
  | `network` | Docker default bridge | Existing Docker network to join, such as a compose project network, so the agent can reach sibling services by name |
35
35
  | `platform` | Daemon native | Image platform such as `linux/amd64` |
36
36
  | `timeoutMs` | `3600000` | Fixed container lifetime in multiples of `1000` milliseconds, up to `86400000` (24 hours). The container exits and removes itself afterwards |
37
37
  | `cpu` | Unlimited | Positive finite `--cpus` limit |
38
38
  | `memoryMiB` | Unlimited | Positive integer `--memory` limit |
39
39
 
40
- Use the same settings in an Agent. Switching an existing agent between a cloud provider and Docker is a change to `sandbox` only:
40
+ Use the same settings in a `LegacyBundledAgent`. Switching an existing agent between a cloud provider and Docker is a change to `sandbox` only:
41
41
 
42
42
  ```typescript
43
- const agent = new Agent({
43
+ const agent = new LegacyBundledAgent({
44
44
  sandbox: { provider: 'docker', network: 'my-eval_default' },
45
45
  // sourceFile, inputSchema, session, dependencies, localDirectories, etc.
46
46
  });
@@ -54,15 +54,15 @@ On Apple Silicon the default container is `linux/arm64`, while Neckbeard filters
54
54
 
55
55
  ## Attaching to an existing container
56
56
 
57
- `SandboxClient.connect` accepts a container ID or name (kept verbatim as the handle `id`, so `Agent.run(..., { sandboxId })` and `createSession({ sandboxId })` accept names and short IDs too), including containers this provider did not create, such as a service an eval harness or compose file already started:
57
+ `SandboxClient.connect` accepts a container ID or name (kept verbatim as the handle `id`, so `LegacyBundledAgent.run(..., { sandboxId })` and `createSession({ sandboxId })` accept names and short IDs too), including containers this provider did not create, such as a service an eval harness or compose file already started:
58
58
 
59
59
  ```typescript
60
60
  const sandbox = await SandboxClient.connect({ provider: 'docker', sandboxId: 'my-eval-main-1' });
61
61
  ```
62
62
 
63
- Containers created by this provider carry the label `agent-neckbeard.managed=true`. **`destroy()` and `Agent.kill()` remove only labeled containers.** For any other container they are a no-op: the container and its host tunnel are left in place for its owner and for other handles in the process. An attached container must be running, Debian-compatible, and able to run commands as root.
63
+ Containers created by this provider carry the label `agent-neckbeard.managed=true`. **`destroy()` and `LegacyBundledAgent.kill()` remove only labeled containers.** For any other container they are a no-op: the container and its host tunnel are left in place for its owner and for other handles in the process. An attached container must be running, Debian-compatible, and able to run commands as root.
64
64
 
65
- `Agent.deploy()` always creates its own container; deploying an agent into a container owned by another tool is not supported yet. `Agent.run(..., { sandboxId })` and `createSession({ sandboxId })` reconnect to a container that an earlier `deploy()` prepared. To put a deployed agent next to compose services, pass the compose network as `network` instead.
65
+ `LegacyBundledAgent.deploy()` always creates its own container; deploying an agent into a container owned by another tool is not supported yet. `LegacyBundledAgent.run(..., { sandboxId })` and `createSession({ sandboxId })` reconnect to a container that an earlier `deploy()` prepared. To put a deployed agent next to compose services, pass the compose network as `network` instead.
66
66
 
67
67
  ## HTTP access
68
68
 
package/docs/E2B.md ADDED
@@ -0,0 +1,11 @@
1
+ # E2B Provider
2
+
3
+ E2B runs `Agent`, `SandboxClient`, and the deprecated `LegacyBundledAgent`. Set `E2B_API_KEY` on the host, or pass `apiKey` in the sandbox config. The E2B SDK sets the package's minimum host Node.js version; see [host requirements](CONSUMER_ENVIRONMENTS.md#host-requirements).
4
+
5
+ ## Images and templates
6
+
7
+ E2B starts sandboxes from templates. `Agent.prepare()` builds a template named `nb-<name>-<hash>` from the agent's registry image, unless that template already has a ready build (it waits out a build in progress, builds again after a failed one, and builds after a grace period of a quarter of `prepareTimeoutMs`, at most a minute, when a registered build never starts), and `gc({ keep })` deletes this agent's older ones. To pull a private image, pass `sandbox.registry: { username, password }`; E2B uses it only while building the template. A template's start command cannot receive per-sandbox environment, so `Agent` starts the runtime as a background command after the sandbox starts. `cpuCount` and `memoryMB` size the sandbox, and `timeoutMs` sets its lifetime. For `SandboxClient` and `LegacyBundledAgent`, `sandbox.template` names an existing template, such as `code-interpreter-v1`.
8
+
9
+ ## Lifetime, paths, and HTTP
10
+
11
+ `SandboxClient.create()` accepts `timeoutMs`, and E2B is the provider that supports `setTimeout()` to extend a running sandbox's lifetime; other providers throw `ConfigurationError`. The home directory is `/home/user`. Neckbeard sends E2B's traffic token as the `e2b-traffic-access-token` header; callers only store the sandbox ID.