@computesdk/pethost 0.0.0-stage → 1.0.2

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,82 @@
1
- # Temporary Holding Version
1
+ # @computesdk/pethost
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
+ Pethost provider for ComputeSDK: [Pethost Agent Sandboxes](https://pethost.dev/sandboxes/), Firecracker microVMs for AI agents, each with its own Linux kernel. Commands and files go through Pethost's API, a paused sandbox keeps its memory and processes, and a sandbox's disk saves as a template that new sandboxes start from.
4
+
5
+ The default template, `base`, is Ubuntu 24.04 with Python, Node.js, Docker, Claude Code, Codex, OpenCode and a desktop with Chrome. Commands run as `user` in `/home/user`, who has passwordless sudo.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install computesdk @computesdk/pethost
11
+ ```
12
+
13
+ ## Setup
14
+
15
+ In your workspace of sandboxes at [console.pethost.dev](https://console.pethost.dev), press **Connect an agent**, open **TypeScript** and press **Create an API token**. Then:
16
+
17
+ ```bash
18
+ export PETHOST_TOKEN=your_pethost_api_token
19
+ # Only when your account has several workspaces of sandboxes:
20
+ export PETHOST_WORKSPACE=my-workspace
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```typescript
26
+ import { pethost } from '@computesdk/pethost';
27
+
28
+ const compute = pethost({ size: 'SMALL' });
29
+ const sandbox = await compute.instances.create();
30
+
31
+ try {
32
+ const result = await sandbox.runCommand('python3 -c "print(6 * 7)"');
33
+ console.log(result.stdout); // 42
34
+
35
+ await sandbox.filesystem.writeFile('/home/user/app/hello.txt', 'Hello from Pethost');
36
+ console.log(await sandbox.filesystem.readFile('/home/user/app/hello.txt'));
37
+ } finally {
38
+ await sandbox.destroy();
39
+ }
40
+ ```
41
+
42
+ ## Configuration
43
+
44
+ | Option | Meaning |
45
+ | --- | --- |
46
+ | `token` | API token; falls back to `PETHOST_TOKEN` |
47
+ | `workspace` | Workspace id or name, needed when the account has several; falls back to `PETHOST_WORKSPACE` |
48
+ | `baseUrl` | API address; falls back to `PETHOST_URL`, then `https://console.pethost.dev` |
49
+ | `template` | Template new sandboxes start from; default `base` |
50
+ | `size` | `SMALL` (2 vCPU, 4 GiB), `DEFAULT` (4, 8), `LARGE` (8, 16) or `XLARGE` (16, 32); default: the template's, `DEFAULT` for `base` |
51
+ | `timeout` | Deletes a sandbox once it has been idle this many milliseconds (`lifecycle.deleteAfterIdleSeconds`) |
52
+ | `settings` | Native settings for every create: `lifecycle`, `egress`, `ingress`, `environment` |
53
+
54
+ `create()` takes `templateId`, `snapshotId`, `sizeClass` or native `size`, `name`, `envs` (added to the variables of `settings.environment`, workspace secrets among them), `metadata` (stored as labels), `timeout` and native `settings`. It refuses other providers' CPU and memory fields and `image`, rather than ignore them.
55
+
56
+ ## Features
57
+
58
+ | Capability | Notes |
59
+ | --- | --- |
60
+ | `runCommand` | `bash -lc`, with `cwd`, `env`, `timeout` (exit code 124 when it ends a command) and `background` |
61
+ | Live output | `onStdout`/`onStderr` from Pethost's command stream |
62
+ | Processes | `startProcess` through ComputeSDK's shell process runtime |
63
+ | Filesystem | Pethost's file API; files over 1 MiB are read, and over 8 MiB written, through links to the sandbox's server that expire after an hour |
64
+ | `getUrl` | A private port's address (requests send `Pethost-Token`; `getPethostPortLink` returns the token), or a public one with `public: true` |
65
+ | `list`, `getById` | Every sandbox of the workspace that is not deleted |
66
+ | Pause and resume | Memory and processes kept |
67
+ | Snapshots and templates | Pethost templates: the disk and settings, saved while the sandbox runs on; many sandboxes start from one |
68
+ | `sizeClass` | `md`, `lg`, `xl`, `2xl` map to `SMALL`, `DEFAULT`, `LARGE`, `XLARGE`; your plan names the largest |
69
+
70
+ Use `sandbox.getInstance().client`, the [`pethost`](https://www.npmjs.com/package/pethost) SDK's client, for what ComputeSDK does not cover: the desktop, coding agents, secrets and the egress allow-list.
71
+
72
+ ## Notes
73
+
74
+ - A sandbox idle for 5 minutes pauses, and after 30 minutes it stops, keeping its disk. Any command, file call or request to a port wakes a paused one; `getById` wakes one too, since the factory reads its egress pointer through the file API. Change the timers in `settings.lifecycle`.
75
+ - A foreground command that runs past 10 seconds is followed through the command stream. Pethost keeps the newest 64 KiB of a command's output for a late reader, so pass `onStdout`/`onStderr` when a command writes more than that in its first seconds.
76
+ - Templates keep files and settings, not memory; a new version is ready to start from after `snapshot.waitUntilReady(id)`.
77
+ - `template.delete(id)` deletes every version of the id's name: Pethost deletes a name whole. `snapshot.delete(id)` deletes a snapshot whose version is its name's only one, as every name `snapshot.create` gives is, and refuses one that has other versions.
78
+ - Sandboxes run in one region, in the EU. `regionClass` names US areas, so with `regionMode: 'only'` a create fails before it starts, and without it the sandbox runs in the EU.
79
+
80
+ ## Billing
81
+
82
+ Sandboxes are billed by the second at your workspace's plan; a paused one at a lower rate, and a stopped one by the disk it keeps. Delete a sandbox when you are done (`destroy()`), or pass `timeout` to delete it once idle. Docs: [pethost.dev/docs/sandboxes](https://pethost.dev/docs/sandboxes/).
@@ -0,0 +1,73 @@
1
+ import { CreateTemplateOptions, Provider, ProviderSnapshotManager, ProviderTemplateManager, InstanceSizeManager } from '@computesdk/provider';
2
+ import { Sandboxes, Sandbox, Size, SandboxSettingsInput, Link } from 'pethost/sandboxes';
3
+ export { SandboxSettingsInput as PethostSettings, Size as PethostSize } from 'pethost/sandboxes';
4
+
5
+ interface PethostConfig {
6
+ /** API token. Falls back to PETHOST_TOKEN. */
7
+ token?: string;
8
+ /**
9
+ * The workspace of sandboxes, by id or name. Needed only when the token's account has several.
10
+ * Falls back to PETHOST_WORKSPACE.
11
+ */
12
+ workspace?: string;
13
+ /** API address. Falls back to PETHOST_URL, then https://console.pethost.dev. */
14
+ baseUrl?: string;
15
+ /** Template a sandbox starts from when create names none. Default: Pethost's `base`. */
16
+ template?: string;
17
+ /** Size of new sandboxes: SMALL, DEFAULT, LARGE or XLARGE. Default: the template's (DEFAULT for `base`). */
18
+ size?: Size;
19
+ /**
20
+ * Deletes a sandbox once it has been idle this many milliseconds (lifecycle.deleteAfterIdleSeconds,
21
+ * rounded up to a second). Pethost puts no cap on a sandbox's life, so this counts idle time.
22
+ */
23
+ timeout?: number;
24
+ /** Native settings for every create: lifecycle, egress, ingress, environment. */
25
+ settings?: SandboxSettingsInput;
26
+ }
27
+ /** A sandbox as the provider holds it. */
28
+ interface PethostSandbox {
29
+ /** The client that made or found it: it keeps the sandbox's runtime connection. */
30
+ readonly client: Sandboxes;
31
+ readonly sandboxId: string;
32
+ /** The sandbox's record as the call that returned it answered. */
33
+ readonly record: Sandbox;
34
+ }
35
+
36
+ interface PethostSnapshot {
37
+ /** `name@version`: what create's snapshotId and templateId take. */
38
+ id: string;
39
+ provider: 'pethost';
40
+ createdAt: Date;
41
+ metadata: {
42
+ name: string;
43
+ version: number;
44
+ state: string;
45
+ failureMessage: string;
46
+ sizeBytes: number;
47
+ base: string;
48
+ };
49
+ }
50
+ interface PethostTemplate extends PethostSnapshot {
51
+ /** Same as id. */
52
+ templateId: string;
53
+ builtIn: boolean;
54
+ description: string;
55
+ }
56
+ interface PethostCreateTemplateOptions extends CreateTemplateOptions {
57
+ /** The sandbox whose disk and settings the new version holds. A name that exists gets its next version. */
58
+ sandboxId: string;
59
+ }
60
+
61
+ /** A port's address and a token for it alone, sent as `Pethost-Token: <token>`. */
62
+ declare function getPethostPortLink(sandbox: PethostSandbox, options: {
63
+ port: number;
64
+ ttlSeconds?: number;
65
+ }): Promise<Link>;
66
+ interface PethostProvider extends Provider<PethostSandbox, PethostTemplate, PethostSnapshot> {
67
+ snapshot: ProviderSnapshotManager<PethostSnapshot>;
68
+ template: ProviderTemplateManager<PethostTemplate, PethostCreateTemplateOptions>;
69
+ readonly sizes: InstanceSizeManager;
70
+ }
71
+ declare function pethost(config?: PethostConfig): PethostProvider;
72
+
73
+ export { type PethostConfig, type PethostCreateTemplateOptions, type PethostProvider, type PethostSandbox, type PethostSnapshot, type PethostTemplate, getPethostPortLink, pethost };
@@ -0,0 +1,73 @@
1
+ import { CreateTemplateOptions, Provider, ProviderSnapshotManager, ProviderTemplateManager, InstanceSizeManager } from '@computesdk/provider';
2
+ import { Sandboxes, Sandbox, Size, SandboxSettingsInput, Link } from 'pethost/sandboxes';
3
+ export { SandboxSettingsInput as PethostSettings, Size as PethostSize } from 'pethost/sandboxes';
4
+
5
+ interface PethostConfig {
6
+ /** API token. Falls back to PETHOST_TOKEN. */
7
+ token?: string;
8
+ /**
9
+ * The workspace of sandboxes, by id or name. Needed only when the token's account has several.
10
+ * Falls back to PETHOST_WORKSPACE.
11
+ */
12
+ workspace?: string;
13
+ /** API address. Falls back to PETHOST_URL, then https://console.pethost.dev. */
14
+ baseUrl?: string;
15
+ /** Template a sandbox starts from when create names none. Default: Pethost's `base`. */
16
+ template?: string;
17
+ /** Size of new sandboxes: SMALL, DEFAULT, LARGE or XLARGE. Default: the template's (DEFAULT for `base`). */
18
+ size?: Size;
19
+ /**
20
+ * Deletes a sandbox once it has been idle this many milliseconds (lifecycle.deleteAfterIdleSeconds,
21
+ * rounded up to a second). Pethost puts no cap on a sandbox's life, so this counts idle time.
22
+ */
23
+ timeout?: number;
24
+ /** Native settings for every create: lifecycle, egress, ingress, environment. */
25
+ settings?: SandboxSettingsInput;
26
+ }
27
+ /** A sandbox as the provider holds it. */
28
+ interface PethostSandbox {
29
+ /** The client that made or found it: it keeps the sandbox's runtime connection. */
30
+ readonly client: Sandboxes;
31
+ readonly sandboxId: string;
32
+ /** The sandbox's record as the call that returned it answered. */
33
+ readonly record: Sandbox;
34
+ }
35
+
36
+ interface PethostSnapshot {
37
+ /** `name@version`: what create's snapshotId and templateId take. */
38
+ id: string;
39
+ provider: 'pethost';
40
+ createdAt: Date;
41
+ metadata: {
42
+ name: string;
43
+ version: number;
44
+ state: string;
45
+ failureMessage: string;
46
+ sizeBytes: number;
47
+ base: string;
48
+ };
49
+ }
50
+ interface PethostTemplate extends PethostSnapshot {
51
+ /** Same as id. */
52
+ templateId: string;
53
+ builtIn: boolean;
54
+ description: string;
55
+ }
56
+ interface PethostCreateTemplateOptions extends CreateTemplateOptions {
57
+ /** The sandbox whose disk and settings the new version holds. A name that exists gets its next version. */
58
+ sandboxId: string;
59
+ }
60
+
61
+ /** A port's address and a token for it alone, sent as `Pethost-Token: <token>`. */
62
+ declare function getPethostPortLink(sandbox: PethostSandbox, options: {
63
+ port: number;
64
+ ttlSeconds?: number;
65
+ }): Promise<Link>;
66
+ interface PethostProvider extends Provider<PethostSandbox, PethostTemplate, PethostSnapshot> {
67
+ snapshot: ProviderSnapshotManager<PethostSnapshot>;
68
+ template: ProviderTemplateManager<PethostTemplate, PethostCreateTemplateOptions>;
69
+ readonly sizes: InstanceSizeManager;
70
+ }
71
+ declare function pethost(config?: PethostConfig): PethostProvider;
72
+
73
+ export { type PethostConfig, type PethostCreateTemplateOptions, type PethostProvider, type PethostSandbox, type PethostSnapshot, type PethostTemplate, getPethostPortLink, pethost };