@computesdk/cocoonstack 0.0.0-stage → 1.0.1

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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 computesdk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,104 @@
1
- # Temporary Holding Version
1
+ # @computesdk/cocoonstack
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
+ Cocoon Stack provider for ComputeSDK - self-hosted microVM sandboxes served from warm pools by [sandboxd](https://github.com/cocoonstack/sandbox), the sandbox control plane of the Cocoon Stack.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @computesdk/cocoonstack
9
+ ```
10
+
11
+ ## Setup
12
+
13
+ 1. Run a sandboxd node (see the [deployment guide](https://github.com/cocoonstack/sandbox/blob/main/docs/deploy.md)) with a pool for the template you want to claim, and put it behind TLS.
14
+ 2. Set the endpoint and a node or tenant API token:
15
+
16
+ ```bash
17
+ export COCOONSTACK_API_URL=https://sandbox.example.com
18
+ export COCOONSTACK_API_KEY=your_api_token
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ```typescript
24
+ import { compute } from 'computesdk';
25
+ import { cocoonstack } from '@computesdk/cocoonstack';
26
+
27
+ compute.setConfig({
28
+ provider: cocoonstack({
29
+ baseUrl: process.env.COCOONSTACK_API_URL,
30
+ apiKey: process.env.COCOONSTACK_API_KEY,
31
+ }),
32
+ });
33
+
34
+ const sandbox = await compute.sandbox.create();
35
+
36
+ const result = await sandbox.runCommand('node -v');
37
+ console.log(result.stdout);
38
+
39
+ await sandbox.destroy();
40
+ ```
41
+
42
+ Or call the provider factory directly:
43
+
44
+ ```typescript
45
+ import { cocoonstack } from '@computesdk/cocoonstack';
46
+
47
+ const sdk = cocoonstack({ baseUrl: process.env.COCOONSTACK_API_URL, apiKey: process.env.COCOONSTACK_API_KEY });
48
+ const sandbox = await sdk.sandbox.create({ templateId: 'python-rt:3.12', vcpus: 4, memoryMb: 4096 });
49
+ ```
50
+
51
+ ## Configuration
52
+
53
+ ```typescript
54
+ interface CocoonstackConfig {
55
+ /** sandboxd endpoint - if not provided, will use COCOONSTACK_API_URL env var */
56
+ baseUrl?: string;
57
+ /** Node or tenant API token - if not provided, will use COCOONSTACK_API_KEY env var */
58
+ apiKey?: string;
59
+ /** Default template, a pool key such as node-rt:24.04 (the default) */
60
+ template?: string;
61
+ /** Default network lane: 'none' (default) or 'egress' */
62
+ net?: 'none' | 'egress';
63
+ /** Default size tier: small (default), medium, large, xlarge, 2xlarge */
64
+ size?: 'small' | 'medium' | 'large' | 'xlarge' | '2xlarge';
65
+ /** Default claim lease in seconds (default 300); the node reaps the sandbox after it */
66
+ ttlSeconds?: number;
67
+ /** HTTP request timeout in milliseconds (default 120000) */
68
+ requestTimeoutMs?: number;
69
+ /** Open the HTTP/2 session at construction; TLS endpoints only (default false) */
70
+ preconnect?: boolean;
71
+ }
72
+ ```
73
+
74
+ ### Create options
75
+
76
+ - `templateId` (or `image`) picks the template, e.g. `node-rt:24.04`, `python-rt:3.12`, `rt:24.04`.
77
+ - `size` picks a tier by name. Without it, `vcpus`/`cpus`/`cpu` and `memoryMb`/`memoryMiB`/`memMiB`/`memory` map to the smallest tier that covers the request:
78
+
79
+ | size | CPU | memory |
80
+ |---|---|---|
81
+ | `small` | 1 | 512 MB |
82
+ | `medium` | 2 | 1 GB |
83
+ | `large` | 4 | 4 GB |
84
+ | `xlarge` | 4 | 8 GB |
85
+ | `2xlarge` | 8 | 16 GB |
86
+
87
+ - `timeout` (milliseconds) becomes the claim lease, capped at 24 hours.
88
+
89
+ A claim is served from the node's warm pool for `(template, net, size)`; a request outside the configured pools cold-boots the template, which takes longer.
90
+
91
+ ## Features
92
+
93
+ - ✅ **Command Execution** - commands run as root through `bash -c` over the sandboxd agent relay, with native `cwd`, `env`, streaming `onStdout`/`onStderr`, `background`, and `timeout`
94
+ - ✅ **Filesystem Operations** - shell-backed `readFile`, `writeFile`, `mkdir`, `readdir`, `exists`, `remove`
95
+ - ✅ **Preview URLs** - `getUrl` mints a signed preview URL when the node has a preview listener
96
+ - ✅ **Listing** - `list` and `getById` read the node's sandbox index
97
+
98
+ ## Limitations
99
+
100
+ - sandboxd scopes a sandbox to the token minted at claim time, so `getById` and `list` return only the sandboxes this process claimed (the node's own index is visible through the sandboxd API). `destroy` by id also works with a node token.
101
+ - A command without an explicit `timeout` is bounded by `requestTimeoutMs` (120 s by default); pass `timeout` for longer builds.
102
+ - Tokens travel as bearer headers: use an `https://` endpoint outside a private network. Nothing connects until the first call; `preconnect: true` opens the HTTP/2 session when the factory runs instead, so the first sandbox call skips DNS and the TLS handshake.
103
+ - A node in a cluster may answer a claim with a redirect to a peer; this provider refuses it. Point `baseUrl` at a node that serves the pool.
104
+ - Snapshots and templates are managed through sandboxd's own API (checkpoints, promote) and are not exposed here.
@@ -0,0 +1,66 @@
1
+ import * as computesdk from 'computesdk';
2
+ import * as _computesdk_provider from '@computesdk/provider';
3
+
4
+ declare const SIZES: readonly [{
5
+ readonly size: "small";
6
+ readonly cpu: 1;
7
+ readonly memoryMb: 512;
8
+ }, {
9
+ readonly size: "medium";
10
+ readonly cpu: 2;
11
+ readonly memoryMb: 1024;
12
+ }, {
13
+ readonly size: "large";
14
+ readonly cpu: 4;
15
+ readonly memoryMb: 4096;
16
+ }, {
17
+ readonly size: "xlarge";
18
+ readonly cpu: 4;
19
+ readonly memoryMb: 8192;
20
+ }, {
21
+ readonly size: "2xlarge";
22
+ readonly cpu: 8;
23
+ readonly memoryMb: 16384;
24
+ }];
25
+ type CocoonstackSize = (typeof SIZES)[number]['size'];
26
+ type CocoonstackNet = 'none' | 'egress';
27
+ interface CocoonstackConfig {
28
+ /** sandboxd endpoint, e.g. https://sandbox.example.com. Falls back to COCOONSTACK_API_URL. */
29
+ baseUrl?: string;
30
+ /** Node or tenant API token. Falls back to COCOONSTACK_API_KEY. */
31
+ apiKey?: string;
32
+ /** Default template, a pool key such as node-rt:24.04. */
33
+ template?: string;
34
+ /** Default network lane. */
35
+ net?: CocoonstackNet;
36
+ /** Default size tier. */
37
+ size?: CocoonstackSize;
38
+ /** Default claim lease in seconds; the node reaps the sandbox after it. */
39
+ ttlSeconds?: number;
40
+ /** HTTP request timeout. */
41
+ requestTimeoutMs?: number;
42
+ /** Open the HTTP/2 session at construction so the first call skips DNS and the TLS handshake; TLS endpoints only. */
43
+ preconnect?: boolean;
44
+ }
45
+ interface CocoonstackSandbox {
46
+ id: string;
47
+ /** The claim token; every call on the sandbox authenticates with it. */
48
+ token: string;
49
+ template: string;
50
+ net: CocoonstackNet;
51
+ size: CocoonstackSize;
52
+ createdAt: Date;
53
+ deadline: Date;
54
+ config: CocoonstackConfig;
55
+ }
56
+ declare class CocoonstackApiError extends Error {
57
+ readonly status: number;
58
+ constructor(status: number, message: string);
59
+ }
60
+ declare const provider: (config: CocoonstackConfig & _computesdk_provider.ProcessRuntimeOptions) => _computesdk_provider.Provider<CocoonstackSandbox, any, any, computesdk.Volume> & {
61
+ readonly sizes: computesdk.InstanceSizeManager;
62
+ };
63
+ /** Cocoon Stack provider; `preconnect` opens the HTTP/2 session at construction instead of on the first call. */
64
+ declare const cocoonstack: typeof provider;
65
+
66
+ export { CocoonstackApiError, type CocoonstackConfig, type CocoonstackNet, type CocoonstackSandbox, type CocoonstackSize, cocoonstack, cocoonstack as default };
@@ -0,0 +1,66 @@
1
+ import * as computesdk from 'computesdk';
2
+ import * as _computesdk_provider from '@computesdk/provider';
3
+
4
+ declare const SIZES: readonly [{
5
+ readonly size: "small";
6
+ readonly cpu: 1;
7
+ readonly memoryMb: 512;
8
+ }, {
9
+ readonly size: "medium";
10
+ readonly cpu: 2;
11
+ readonly memoryMb: 1024;
12
+ }, {
13
+ readonly size: "large";
14
+ readonly cpu: 4;
15
+ readonly memoryMb: 4096;
16
+ }, {
17
+ readonly size: "xlarge";
18
+ readonly cpu: 4;
19
+ readonly memoryMb: 8192;
20
+ }, {
21
+ readonly size: "2xlarge";
22
+ readonly cpu: 8;
23
+ readonly memoryMb: 16384;
24
+ }];
25
+ type CocoonstackSize = (typeof SIZES)[number]['size'];
26
+ type CocoonstackNet = 'none' | 'egress';
27
+ interface CocoonstackConfig {
28
+ /** sandboxd endpoint, e.g. https://sandbox.example.com. Falls back to COCOONSTACK_API_URL. */
29
+ baseUrl?: string;
30
+ /** Node or tenant API token. Falls back to COCOONSTACK_API_KEY. */
31
+ apiKey?: string;
32
+ /** Default template, a pool key such as node-rt:24.04. */
33
+ template?: string;
34
+ /** Default network lane. */
35
+ net?: CocoonstackNet;
36
+ /** Default size tier. */
37
+ size?: CocoonstackSize;
38
+ /** Default claim lease in seconds; the node reaps the sandbox after it. */
39
+ ttlSeconds?: number;
40
+ /** HTTP request timeout. */
41
+ requestTimeoutMs?: number;
42
+ /** Open the HTTP/2 session at construction so the first call skips DNS and the TLS handshake; TLS endpoints only. */
43
+ preconnect?: boolean;
44
+ }
45
+ interface CocoonstackSandbox {
46
+ id: string;
47
+ /** The claim token; every call on the sandbox authenticates with it. */
48
+ token: string;
49
+ template: string;
50
+ net: CocoonstackNet;
51
+ size: CocoonstackSize;
52
+ createdAt: Date;
53
+ deadline: Date;
54
+ config: CocoonstackConfig;
55
+ }
56
+ declare class CocoonstackApiError extends Error {
57
+ readonly status: number;
58
+ constructor(status: number, message: string);
59
+ }
60
+ declare const provider: (config: CocoonstackConfig & _computesdk_provider.ProcessRuntimeOptions) => _computesdk_provider.Provider<CocoonstackSandbox, any, any, computesdk.Volume> & {
61
+ readonly sizes: computesdk.InstanceSizeManager;
62
+ };
63
+ /** Cocoon Stack provider; `preconnect` opens the HTTP/2 session at construction instead of on the first call. */
64
+ declare const cocoonstack: typeof provider;
65
+
66
+ export { CocoonstackApiError, type CocoonstackConfig, type CocoonstackNet, type CocoonstackSandbox, type CocoonstackSize, cocoonstack, cocoonstack as default };