@agentproto/sandbox-instabox 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,70 @@
1
- # Temporary Holding Version
1
+ # @agentproto/sandbox-instabox
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ InstaBox `SandboxProvider` for `@agentproto/sandbox` (https://instabox.sh, API
4
+ https://api.instabox.sh). Boots an InstaBox VM (`universal` template by
5
+ default: Debian 13, git, gh, Node 22, Python, Go, Rust, Docker, Claude Code,
6
+ Codex), installs an always-on `systemd` unit for the agentproto daemon
7
+ (`Restart=always`, brokered secrets in a root-owned 0600 `EnvironmentFile`),
8
+ publishes the daemon port through the account's public edge, and exposes its
9
+ MCP endpoint as a URL, so `createSandboxAgentSessionHost` can hand it straight
10
+ to `connectDaemonAgentSessionHost` (`@agentproto/worktree`) and run any
11
+ `AgentStep` inside the sandbox, unchanged.
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { createSandboxAgentSessionHost } from "@agentproto/sandbox"
17
+ import { instaboxSandboxProvider } from "@agentproto/sandbox-instabox"
18
+ import { runWorkflow } from "@agentproto/workflow-runtime"
19
+ import { worktreeAgentWorkflow } from "@agentproto/worktree"
20
+
21
+ const host = await createSandboxAgentSessionHost({
22
+ provider: instaboxSandboxProvider,
23
+ spec: { provider: "instabox", config: {} },
24
+ secrets: { slugs: ["OPENROUTER_API_KEY"] },
25
+ })
26
+ try {
27
+ await runWorkflow({ workflow: worktreeAgentWorkflow, input, agents: host })
28
+ } finally {
29
+ await host.stop()
30
+ }
31
+ ```
32
+
33
+ Requires `INSTABOX_API_KEY` in the host process's environment (or
34
+ `spec.config.apiKey`; both are read from there, e.g.
35
+ `{ provider: "instabox", apiKey: "ibk_..." }` via `setup_sandbox_provider`).
36
+
37
+ ## Notes
38
+
39
+ - The public port edge (a published port at
40
+ `https://{port}-{machineIdWithoutM_}.instabox.tech`) is UNLOCKED at
41
+ InstaBox: the daemon's own bearer token is the only gate on `/mcp`, so the
42
+ unit is started with `--auth-token` whose value is substituted by systemd
43
+ from the 0600 EnvironmentFile (`AGENTPROTO_AUTH_TOKEN`), so the token never
44
+ rides an exec argv. `booted.token` / `.authHeaders` carry it for callers.
45
+ - InstaBox has NO file-upload route: `writeFile` and `readFile` stream base64
46
+ through `exec` (chunks of at most 700 KB, so each stdin/stdout stays under
47
+ the API's 1 MiB cap), with `mkdir -p` creating parents.
48
+ - A background `cmd &` without redirected stdio keeps the synchronous exec
49
+ open until its timeout: the provider never backgrounds anything. The daemon
50
+ runs as a systemd unit (`Restart=always`), which survived `kill -9`,
51
+ suspend/resume and auto-suspend in the measured wiring.
52
+ - A MANUALLY suspended machine does not wake on its own (public URL 503, exec
53
+ and `wake` answer 409), so this provider NEVER sends the suspend verb and
54
+ does NOT implement `pause()`: callers fall back to `stop()`, which deletes
55
+ the machine. The provider requests `autoSuspendAfterSeconds: 0`
56
+ (configurable via `config.autoSuspendAfterSeconds`), but the live API ignores
57
+ 0 and keeps its 1800s window; an auto-suspended box wakes on a public
58
+ request, `wake` or `exec`, and `connect` revives a manually suspended one.
59
+ - Account limit: 5 machines, suspended and stopped ones counting. `boot`
60
+ pre-checks `GET /v1/usage` + `GET /v1/machines` and throws a typed
61
+ `SandboxQuotaError` (fall back to another provider) when the cap is hit.
62
+ - `connect(sandboxId)` is state aware: `running` is a no-op; an auto-suspended
63
+ machine gets `wake`; a manually suspended one falls back to `resume`; a
64
+ stopped one `start`. The daemon bearer is re-derived from the env file, the
65
+ lifetime is re-armed (PATCH `timeoutSeconds` restarts the countdown from
66
+ now), and health is re-verified through the public edge.
67
+
68
+ ## License
69
+
70
+ Apache-2.0 — see [LICENSE](./LICENSE).
@@ -0,0 +1,335 @@
1
+ import { SandboxProvider } from '@agentproto/sandbox';
2
+
3
+ /**
4
+ * Tiny typed InstaBox API client (https://instabox.sh, API
5
+ * https://api.instabox.sh) over injectable `fetch`. Shapes measured on a real
6
+ * account on 2026-10-18:
7
+ *
8
+ * - auth: `X-API-Key: ibk_...` (NEVER logged and never echoed in an error).
9
+ * - every lifecycle verb (`POST /v1/machines`, suspend/resume/stop/start,
10
+ * ports, DELETE) returns 202 `{id:"op_...", machineId, state:"queued"}` and
11
+ * is awaited via `GET /v1/operations/{id}?wait=25s` long-polling.
12
+ * - errors: `{"error":{"code","message","requestId","retryable","operationId"}}`.
13
+ * - a publish-port request is idempotent (201 first, 200 if already
14
+ * published) and both creates get an idempotency header, but `exec` is NOT
15
+ * retried on transport errors.
16
+ */
17
+ /** Machine states reported by `GET /v1/machines/{id}` right now. */
18
+ type InstaboxMachineState = "running" | "suspended" | "stopped";
19
+ /** The action a machine takes when its `timeoutSeconds` lifetime elapses. */
20
+ type InstaboxOnTimeout = "pause" | "kill";
21
+ interface InstaboxMachine {
22
+ /** Canonical id, `m_...` (a GET still accepts the machine NAME for direct
23
+ * lookups, but `files`, `wake` and `ports` need the canonical id). */
24
+ id: string;
25
+ state: InstaboxMachineState | string;
26
+ desiredState?: string;
27
+ name?: string;
28
+ runtime?: {
29
+ ready?: boolean;
30
+ };
31
+ /** ISO timestamp of the current lifetime deadline (null when not Running). */
32
+ timeoutAt?: string | null;
33
+ onTimeout?: InstaboxOnTimeout;
34
+ autoSuspendAfterSeconds?: number;
35
+ metadata?: Record<string, string>;
36
+ /** Pending operation id, or null when the answer is already final. */
37
+ operationId?: string | null;
38
+ }
39
+ type InstaboxOperationState = "queued" | "running" | "succeeded" | "failed" | string;
40
+ interface InstaboxOperation {
41
+ /** Operation id, `op_...`. */
42
+ id: string;
43
+ machineId?: string;
44
+ state: InstaboxOperationState;
45
+ error?: unknown;
46
+ machine?: InstaboxMachine;
47
+ }
48
+ interface InstaboxCreateMachineInput {
49
+ name: string;
50
+ /** Template id. Default `universal` (Debian 13, git, gh, Node 22, Python,
51
+ * Go, Rust, Docker; one fixed 4 vCPU / 8 GB / 20 GB shape). */
52
+ templateId?: string;
53
+ /** Boot from a snapshot instead of a template. Wins over `templateId`. */
54
+ snapshotId?: string;
55
+ timeoutSeconds: number;
56
+ onTimeout: InstaboxOnTimeout;
57
+ /** 0 is requested to disable auto-suspend; the live API ignores it (window
58
+ * stays 1800s). 120..86400 arms it. */
59
+ autoSuspendAfterSeconds: number;
60
+ metadata: Record<string, string>;
61
+ /** ALWAYS false: a vault would write the caller's secrets into a box that
62
+ * runs agent code. */
63
+ vault: false;
64
+ guestUser?: string;
65
+ desiredState?: string;
66
+ }
67
+ interface InstaboxExecInput {
68
+ cmd: string;
69
+ cwd?: string;
70
+ envs?: Record<string, string>;
71
+ /** Feeds the command's stdin. Max 1 MiB. */
72
+ stdin?: string;
73
+ /** 1..600, default 60 (seconds). */
74
+ timeoutSeconds?: number;
75
+ }
76
+ interface InstaboxExecResult {
77
+ stdout: string;
78
+ stderr: string;
79
+ exitCode: number;
80
+ /** True when the exec hit its `timeoutSeconds` (the API still answers 200
81
+ * with exitCode 124). */
82
+ timedOut: boolean;
83
+ /** True when output was clipped by the API's 1 MiB stdout/stderr cap. */
84
+ truncated: boolean;
85
+ }
86
+ interface InstaboxPort {
87
+ id: string;
88
+ port: number;
89
+ /** `https://{port}-{machineIdWithoutM_}.instabox.tech`: stable per
90
+ * (machine, port), PUBLIC with no InstaBox-side authentication. */
91
+ url: string;
92
+ expiresAt?: string | null;
93
+ }
94
+ interface InstaboxUsage {
95
+ limits?: {
96
+ maxMachines?: number;
97
+ };
98
+ [k: string]: unknown;
99
+ }
100
+ /** A typed failure from the InstaBox API. The API key is never part of
101
+ * `message` (transport errors and JSON error bodies carry no credential). */
102
+ declare class InstaboxApiError extends Error {
103
+ readonly status: number | null;
104
+ readonly code: string;
105
+ readonly requestId?: string;
106
+ readonly retryable?: boolean;
107
+ readonly operationId?: string;
108
+ constructor(message: string, info: {
109
+ status: number | null;
110
+ code: string;
111
+ requestId?: string;
112
+ retryable?: boolean;
113
+ operationId?: string;
114
+ });
115
+ }
116
+ interface InstaboxClientOpts {
117
+ /** API key (`ibk_...`). Sent only as the `X-API-Key` request header. */
118
+ apiKey: string;
119
+ /** Default `https://api.instabox.sh`. */
120
+ apiUrl?: string;
121
+ /** Injectable fetch for tests. */
122
+ fetchImpl?: typeof fetch;
123
+ /** Delay between a failed transport attempt and the retry, ms (backoff
124
+ * branches on it). */
125
+ retryDelayMs?: (attempt: number) => Promise<void>;
126
+ }
127
+ /** True by rules measured in the official CLI: HTTP 402/403/429, or a code or
128
+ * message mentioning "quota" or "limit", means this ACCOUNT is out of room
129
+ * (the limit is 5 machines, suspended and stopped ones included). */
130
+ declare function isInstaboxQuotaFailure(status: number | null, code: string, message: string): boolean;
131
+ /**
132
+ * Typed InstaBox client. Transport errors on ONE-SHOT local calls are mapped
133
+ * to an `InstaboxApiError` with `code: "transport_error"`; only the
134
+ * operation-waiter retries (with backoff). `exec` is never auto-retried: a
135
+ * retry could run a mutating command twice.
136
+ */
137
+ declare class InstaboxClient {
138
+ private readonly apiKey;
139
+ private readonly apiUrl;
140
+ private readonly fetchImpl;
141
+ private readonly retryDelayMs;
142
+ constructor(opts: InstaboxClientOpts);
143
+ private request;
144
+ /** POST /v1/machines. Retried on TRANSPORT errors only (idempotency key is
145
+ * fixed per instance call, so a retry after a lost response cannot mint a
146
+ * duplicate machine). Applied to the network-safe envelope, then the 202
147
+ * body is returned. */
148
+ createMachine(input: InstaboxCreateMachineInput, idempotencyKey: string): Promise<InstaboxOperation>;
149
+ /** GET /v1/operations/{id}?wait=25s, with an overall timeout and retryable
150
+ * transport-error backoff. */
151
+ waitForOperation(operationId: string, timeoutMs?: number): Promise<InstaboxOperation>;
152
+ /** GET /v1/machines/{id} (accepts id or name; ports/wake/files need `id`). */
153
+ getMachine(idOrName: string): Promise<InstaboxMachine>;
154
+ /** GET /v1/machines?metadata=k:v&...&limit=N. */
155
+ listMachines(metadata: Record<string, string>, limit?: number): Promise<InstaboxMachine[]>;
156
+ /** GET /v1/usage (limits.maxMachines). */
157
+ readUsage(): Promise<InstaboxUsage>;
158
+ /** PATCH /v1/machines/{id}. Answers 200 with the updated MACHINE (measured
159
+ * live: `operationId` is null, there is no operation to wait on), so the
160
+ * machine's own `id` must never be handed to `waitForOperation`. A pending
161
+ * `operationId` is still awaited if the API ever returns one. */
162
+ patchMachine(id: string, patch: {
163
+ timeoutSeconds?: number;
164
+ onTimeout?: InstaboxOnTimeout;
165
+ } | {
166
+ autoSuspendAfterSeconds: number;
167
+ }, idempotencyKey?: string): Promise<InstaboxMachine>;
168
+ /** DELETE /v1/machines/{id}. The API rejects a DELETE without an
169
+ * `Idempotency-Key` (HTTP 400), so one is always sent. */
170
+ deleteMachine(id: string): Promise<InstaboxOperation>;
171
+ /** POST /v1/machines/{id}/ports {port}. 201 first, 200 if already published
172
+ * (both answer the same body). */
173
+ publishPort(id: string, port: number): Promise<InstaboxPort>;
174
+ /** DELETE /v1/machines/{id}/ports/{port}. */
175
+ deletePort(id: string, port: number): Promise<void>;
176
+ /** POST /v1/machines/{id}/{verb} for suspend|resume|stop|start. */
177
+ machineAction(id: string, verb: "suspend" | "resume" | "stop" | "start"): Promise<InstaboxOperation>;
178
+ /** POST /v1/machines/{id}/wake: 200 DIRECT (no operation to wait on). */
179
+ wake(id: string): Promise<unknown>;
180
+ /** POST /v1/machines/{id}/exec. NEVER retried and NEVER idempotent: a
181
+ * retry could double-run a mutating command. */
182
+ exec(id: string, input: InstaboxExecInput): Promise<InstaboxExecResult>;
183
+ }
184
+ /** Transport errors (never an HTTP status answer) and 5xx. */
185
+ declare function isTransientInstaboxError(err: unknown): boolean;
186
+
187
+ /**
188
+ * InstaBox `SandboxProvider` (https://instabox.sh, API
189
+ * https://api.instabox.sh) for @agentproto/sandbox — boots an InstaBox VM,
190
+ * publishes the agentproto daemon behind the account's public edge, and hands
191
+ * its `/mcp` endpoint to `createSandboxAgentSessionHost` the same way
192
+ * `@agentproto/sandbox-box` (ascii.dev Box) does.
193
+ *
194
+ * Shape notes measured live on 2026-10-18 (see `api.ts` for the API itself):
195
+ *
196
+ * - Synchronous `exec` API (`POST /machines/{id}/exec`): a non-zero exit is a
197
+ * normal 200 RESULT (not an error); a command that runs past its
198
+ * `timeoutSeconds` answers with `exitCode: 124, timedOut: true`; each
199
+ * stream is capped at 1 MiB (`truncated: true`). There is NO upload route
200
+ * (PUT/POST on `/files` 404), so `writeFile`/`readFile` go through `exec`:
201
+ * write = `mkdir -p` + base64 on STDIN to `base64 -d > file` in chunks of at
202
+ * most 700 KB; read = `dd` slice + `base64 -w0` in chunks small enough that
203
+ * each stdout stays under the API's 1 MiB capture cap.
204
+ * - A published port's edge (`https://{port}-{machineIdWithoutM_}.instabox.tech`,
205
+ * stable per machine+port) is PUBLIC with NO InstaBox-side authentication,
206
+ * so the daemon MUST be started with an auth token: the unit's ExecStart
207
+ * carries `--auth-token`, whose value is ONLY substituted by systemd from
208
+ * the EnvironmentFile (`AGENTPROTO_AUTH_TOKEN`), so the token never lands in
209
+ * an exec command's argv; secrets ride the heredoc body (exec stdin) into a
210
+ * root-owned 0600 EnvironmentFile.
211
+ * - Backgrounded in-VM processes MUST redirect their stdio: a bare `cmd &`
212
+ * keeps the synchronous exec open until its timeout. The provider never
213
+ * backgrounds anything itself: the daemon runs as a systemd unit
214
+ * (`Restart=always`), which survives `kill -9`, suspend/resume and
215
+ * auto-suspend (proven live).
216
+ * - A MANUALLY suspended machine does NOT wake on its own: its public URL
217
+ * 503s, its exec and `wake` answer 409. This provider therefore NEVER sends
218
+ * the suspend verb and deliberately does NOT implement `pause()` (omitting
219
+ * it lets callers fall back to `stop()`, which deletes the box). Instead it
220
+ * requests `autoSuspendAfterSeconds` 0 by default (configurable), but the
221
+ * live API ignores 0 (the window stays 1800s) and a PATCH of it is a no-op:
222
+ * do not rely on it. Auto-suspended machines DO wake on a public request,
223
+ * on `wake` and on `exec`, and `connect` revives a manually suspended one
224
+ * through `resume` (proven live: process memory survives).
225
+ */
226
+
227
+ declare const ENV_FILE_PATH = "/etc/agentproto/agentproto.env";
228
+ declare const SYSTEMD_UNIT_PATH = "/etc/systemd/system/agentproto.service";
229
+ /** Unit name of the systemd service wrapping the daemon. */
230
+ declare const DAEMON_UNIT_NAME = "agentproto";
231
+ /** Env var the EnvironmentFile sets for the unit's `--auth-token` value. */
232
+ declare const AUTH_TOKEN_ENV_VAR = "AGENTPROTO_AUTH_TOKEN";
233
+ /** Machine metadata stamp: which machines this provider owns (`agentproto: "1"`). */
234
+ declare const AGENTPROTO_METADATA_KEY = "agentproto";
235
+ /** Suffix that MANDATORY redirection takes on any in-box background
236
+ * invocation (a background `cmd &` without it keeps the synchronous exec
237
+ * open until its timeout). Exported so tests can assert every provider-built
238
+ * command that backgrounds something carries it. */
239
+ declare const BACKGROUND_REDIRECT = ">/dev/null 2>&1 </dev/null";
240
+ interface InstaboxSandboxSpecConfig {
241
+ /** InstaBox API key (`ibk_...`). Falls back to `INSTABOX_API_KEY` in the
242
+ * host process env. Sent only as the `X-API-Key` header (never logged,
243
+ * never part of an error message). */
244
+ apiKey?: string;
245
+ /** Default `https://api.instabox.sh`. */
246
+ apiUrl?: string;
247
+ /** Template id. Default `universal`. (A `snapshotId` would win on the API,
248
+ * but this provider always boots from a template.) */
249
+ template?: string;
250
+ /** Machine lifetime in seconds, re-armed from now on every extend.
251
+ * Default 3600, clamp 60..86400. */
252
+ timeoutSeconds?: number;
253
+ /** This provider only ever sends `kill`: `pause` would leave a manually
254
+ * suspended box stranded (it does not wake on its own). */
255
+ onTimeout?: "kill";
256
+ /** 0 disables auto-suspend (default); 120..86400 arms it. */
257
+ autoSuspendAfterSeconds?: number;
258
+ /** Port the agentproto daemon listens on inside the box. Default 18790. */
259
+ port?: number;
260
+ /** `--workspace` passed to `agentproto serve`. Default `/data/home`. */
261
+ workspace?: string;
262
+ /** CLI version pinned on boot, instead of a floating `@latest`.
263
+ * Produces `@agentproto/cli@<version>`. */
264
+ cliVersion?: string;
265
+ /** Run `npm i -g @agentproto/cli@...` before installing the systemd unit.
266
+ * Default true. Skipped when the health probe finds the daemon already up. */
267
+ updateCliOnBoot?: boolean;
268
+ /** Extra npm package specs installed globally ALONGSIDE the CLI update
269
+ * (one `npm i -g`). Ignored when `updateCliOnBoot` is false or the daemon
270
+ * was already up. */
271
+ installPackages?: string[];
272
+ /** Timeout (seconds, exec-clamped 1..600) for the `npm i -g` update. */
273
+ updateCliTimeoutSeconds?: number;
274
+ /** How long to wait for the machine itself to reach `runtime.ready`. */
275
+ readyTimeoutMs?: number;
276
+ /** How long to wait for the daemon to become healthy after starting it. */
277
+ daemonReadyTimeoutMs?: number;
278
+ /** Extra machine metadata written at create time (merged with the
279
+ * provider's own `agentproto: "1"` stamp). */
280
+ metadata?: Record<string, string>;
281
+ /** Extra shell commands host-executed after the boot update, before the
282
+ * daemon starts. Runs on EVERY boot/connect; entries must be idempotent. */
283
+ setupCommands?: string[];
284
+ }
285
+ /** The EnvironmentFile body: resolved secrets from `opts.env` PLUS the token
286
+ * gating the public edge. Never rendered into a command line. */
287
+ declare function environmentFileContents(env: Record<string, string>, authToken: string): string;
288
+ /**
289
+ * One shell command that writes the daemon's EnvironmentFile (root, 0600)
290
+ * and its systemd unit, BOTH through heredocs. No secret is ever part of an
291
+ * argv token: the env content sits inside the heredoc body (which the exec
292
+ * API turns into `sudo tee`'s stdin), and the unit's ExecStart references the
293
+ * token as `${AGENTPROTO_AUTH_TOKEN}`, substituted by systemd from the
294
+ * EnvironmentFile. Heredoc terminators must sit on their own lines (the same
295
+ * live-tested lesson as `@agentproto/sandbox-box`'s writeSystemdUnitCommand:
296
+ * chaining " && " after a heredoc lands the next command INSIDE it and the
297
+ * unit write silently no-ops at exit 0).
298
+ */
299
+ declare function writeDaemonUnitCommand(port: number, workspace: string, env: Record<string, string>, authToken: string): {
300
+ command: string;
301
+ envFileContents: string;
302
+ unitContents: string;
303
+ };
304
+ /** The global install command line (exported for tests: only package spec
305
+ * names, never a secret). The box user is the unprivileged `user` and the
306
+ * npm prefix is the root-owned /usr/local (measured live: a bare `npm i -g`
307
+ * dies with EACCES), so it runs through `sudo`, keeping the caller's PATH
308
+ * because `sudo`'s secure_path may not list node's directory. */
309
+ declare function buildCliInstallCommand(cliVersion: string, extras: string[]): string;
310
+ /**
311
+ * Quota gate, run BEFORE creating anything: the account limit is 5 machines
312
+ * and suspended/stopped ones count against it, so a pre-check (`GET /v1/usage`
313
+ * + `GET /v1/machines`) catches the common case early and throws a typed
314
+ * `SandboxQuotaError` a caller can fall back to another provider on. The
315
+ * calls are best-effort: a usage API that does not answer must not break a
316
+ * boot that the create call could still grant.
317
+ */
318
+ declare function assertQuotaAvailable(client: InstaboxClient): Promise<void>;
319
+ /** Re-map a create/lifecycle failure that is quota-shaped (HTTP 402/403/429,
320
+ * or a code/message containing "quota" or "limit"; the string exists in the
321
+ * official CLI but was never received live) to `SandboxQuotaError`, so a
322
+ * caller falls back to a different provider instead of surfacing the noise. */
323
+ declare function normalizeQuotaError(err: unknown): unknown;
324
+ /**
325
+ * `createInstaboxSandboxProvider(config)` — an AIP-36 `SandboxProvider`
326
+ * factory. `config` seeds every boot/connect's spec.config (a per-spec value
327
+ * wins per field). The bare `instaboxSandboxProvider` export (what the
328
+ * registry wraps) seeds nothing: credentials come from spec.config or the
329
+ * `INSTABOX_API_KEY` env var.
330
+ */
331
+ declare function createInstaboxSandboxProvider(baseConfig?: InstaboxSandboxSpecConfig): SandboxProvider;
332
+ /** Bare provider instance the catalog/registry wraps. */
333
+ declare const instaboxSandboxProvider: SandboxProvider;
334
+
335
+ export { AGENTPROTO_METADATA_KEY, AUTH_TOKEN_ENV_VAR, BACKGROUND_REDIRECT, DAEMON_UNIT_NAME, ENV_FILE_PATH, InstaboxApiError, InstaboxClient, type InstaboxClientOpts, type InstaboxCreateMachineInput, type InstaboxExecInput, type InstaboxExecResult, type InstaboxMachine, type InstaboxMachineState, type InstaboxOnTimeout, type InstaboxOperation, type InstaboxPort, type InstaboxSandboxSpecConfig, type InstaboxUsage, SYSTEMD_UNIT_PATH, assertQuotaAvailable, buildCliInstallCommand, createInstaboxSandboxProvider, environmentFileContents, instaboxSandboxProvider, isInstaboxQuotaFailure, isTransientInstaboxError, normalizeQuotaError, writeDaemonUnitCommand };