@theagenticguy/microvms 0.8.0 → 0.10.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/README.md CHANGED
@@ -1,53 +1,156 @@
1
1
  # @theagenticguy/microvms
2
2
 
3
- Node bindings over `microvms-core`, the client library for AWS Lambda MicroVMs.
3
+ Run coding agents and their tools in sandboxed AWS Lambda MicroVMs. Give each
4
+ task its own Linux workspace, execute commands, collect files, and terminate
5
+ the VM from JavaScript or TypeScript. `AgentVm` runs Claude Code or Codex
6
+ through Amazon Bedrock; `Sandbox` supports your own agent or command runner.
4
7
 
5
- ```bash
8
+ ## Install
9
+
10
+ ```sh
6
11
  npm install @theagenticguy/microvms
7
12
  ```
8
13
 
9
- A prebuilt native addon per platform, selected through `optionalDependencies`. No compiler
10
- and no install-time download script runs on a consumer's machine.
14
+ Requires Node.js **22.13.0+**. Native addons ship for Linux x64/ARM64 (glibc),
15
+ macOS Apple Silicon, and Windows x64. TypeScript declarations are included.
11
16
 
12
- Requires Node >= 22.13.
17
+ ## Run your first command
13
18
 
14
- ## Async-native
19
+ With an existing image and AWS credentials, this is the 90-second path to a
20
+ working SDK example. One-time AWS setup and image builds take longer.
15
21
 
16
- The core's async surface maps straight through: an exported `async` function runs on napi's
17
- managed runtime and returns a real `Promise`, with an error rejecting it. Exec output and
18
- stdin are handed across as `ReadableStream<Uint8Array>` rather than as async iterators a
19
- consumer would have to adapt.
22
+ You need Lambda MicroVMs access, your normal AWS credential configuration,
23
+ and an execution role. Follow [AWS setup](https://laithalsaadoon.github.io/microvms-agentd/learn/tutorial/first-run/)
24
+ to set `AWS_REGION` and `MICROVM_EXECUTION_ROLE_ARN`. Then use the
25
+ [CLI](https://laithalsaadoon.github.io/microvms-agentd/learn/tutorial/install/)
26
+ to prepare an image containing `agentd`:
20
27
 
21
- ## The traps are in the types
28
+ ```sh
29
+ microvm build --name agent-tools --json
30
+ export MICROVM_IMAGE='paste data.imageIdentifier from the result'
31
+ ```
22
32
 
23
- The constraints the platform enforces at runtime are shapes this package refuses to
24
- construct: a raw token cannot be passed where a session is expected, and a dollar amount is
25
- never a bare float. Each planted bypass has a test that goes red if the door reopens.
33
+ Use the **image ARN**, in the same account and region as your credentials.
34
+ The CLI can resolve image names; the SDK example takes the ARN directly.
35
+ The CLI provisions `agentd` and uploads the build artifact for you.
36
+ Shell examples use Bash or Zsh; in PowerShell, set variables with `$env:NAME='value'`.
37
+
38
+ Save as `hello.mjs`:
39
+
40
+ ```js
41
+ import { Region, Sandbox } from '@theagenticguy/microvms';
42
+
43
+ const imageIdentifier = process.env.MICROVM_IMAGE;
44
+ const executionRoleArn = process.env.MICROVM_EXECUTION_ROLE_ARN;
45
+ if (!imageIdentifier || !executionRoleArn) {
46
+ throw new Error('Set MICROVM_IMAGE and MICROVM_EXECUTION_ROLE_ARN first');
47
+ }
48
+ const vm = await Sandbox.create(Region.parse(process.env.AWS_REGION ?? 'us-east-1'));
49
+ try {
50
+ const session = await vm.run({ imageIdentifier, executionRoleArn });
51
+ const result = await session.runSync(['echo', 'hello from a sandbox']);
52
+ process.stdout.write(result.stdout);
53
+ process.stderr.write(result.stderr);
54
+ if (!result.ok) process.exitCode = 1;
55
+ } finally {
56
+ const cleanup = await vm.terminate();
57
+ if (cleanup.failures.length || cleanup.undeleted.length) {
58
+ console.error('Cleanup needs attention:', cleanup);
59
+ process.exitCode = 1;
60
+ }
61
+ }
62
+ ```
26
63
 
27
- ## Coding agents in a VM
64
+ ```sh
65
+ node hello.mjs
66
+ ```
28
67
 
29
- `AgentVm` is the L3 layer over the sandbox: an image with Claude Code and/or Codex CLI in
30
- it, a launch with egress, a Bedrock bearer token minted in process and installed as a file
31
- the agent sources, and one method that hands the agent a task as uid 1000 in `/workspace`.
68
+ Expected output: `hello from a sandbox`. The VM is terminated after the
69
+ command; the image stays available for reuse. `terminate()` returns once
70
+ termination is accepted by default. Pass `{ waitForTerminated: true }` to
71
+ wait for the final state. Inspect `failures` and `undeleted` because cleanup
72
+ reports failures in its result.
32
73
 
33
- ```ts
34
- const vm = await AgentVm.create(Region.usEast1(), [{ agent: 'codex' }]);
35
- await vm.launch({ imageIdentifier: imageArn, executionRoleArn: role });
36
- await vm.installAccess();
37
- console.log((await vm.promptSync('codex', 'Create hello.py that prints hello, run it.')).stdout);
38
- await vm.terminate();
39
- ```
74
+ ## Run a coding agent
40
75
 
41
- `findImage`, `imageName`, `buildArtifact`, and `buildImage` cover the image, with the S3
42
- upload left to you. `installedAgents`, `installAgentAccess`, and `promptAgent` do the same
43
- over a bare `Session` for a process that holds only the identifier triple.
76
+ First prepare a Claude Code image using the same AWS setup plus
77
+ [Bedrock permissions](https://laithalsaadoon.github.io/microvms-agentd/learn/operations/run-coding-agents-on-bedrock/).
78
+ This builds or reuses the agent image and starts a temporary VM. Capture
79
+ only its image ARN, then terminate that temporary VM:
44
80
 
45
- ## Reading
81
+ ```sh
82
+ MICROVM_AGENT_IMAGE="$(microvm agent-up --vm-name sdk-image --agent claude-code --json |
83
+ node -pe 'JSON.parse(require("node:fs").readFileSync(0, "utf8")).data.imageIdentifier')"
84
+ export MICROVM_AGENT_IMAGE
85
+ microvm terminate sdk-image --wait
86
+ ```
46
87
 
47
- - [Documentation](https://laithalsaadoon.github.io/microvms-agentd/)
48
- - [`docs/EMBEDDING.md`](https://github.com/laithalsaadoon/microvms-agentd/blob/main/docs/EMBEDDING.md)
49
- - [`docs/TRUST.md`](https://github.com/laithalsaadoon/microvms-agentd/blob/main/docs/TRUST.md)
88
+ Save as `agent.mjs`. The agent writes a file inside its own VM; the SDK
89
+ downloads that file before cleanup:
90
+
91
+ ```js
92
+ import { writeFile } from 'node:fs/promises';
93
+ import { AgentVm, Region } from '@theagenticguy/microvms';
94
+
95
+ const imageIdentifier = process.env.MICROVM_AGENT_IMAGE;
96
+ const executionRoleArn = process.env.MICROVM_EXECUTION_ROLE_ARN;
97
+ if (!imageIdentifier || !executionRoleArn) {
98
+ throw new Error('Set MICROVM_AGENT_IMAGE and MICROVM_EXECUTION_ROLE_ARN first');
99
+ }
100
+ const vm = await AgentVm.create(Region.parse(process.env.AWS_REGION ?? 'us-east-1'));
101
+ try {
102
+ const session = await vm.launch({ imageIdentifier, executionRoleArn });
103
+ await vm.installAccess();
104
+ const result = await vm.promptSync(
105
+ 'claude-code',
106
+ 'Create /workspace/hello.py that prints hello from a sandbox. Run it.',
107
+ );
108
+ process.stdout.write(result.stdout);
109
+ process.stderr.write(result.stderr);
110
+ if (!result.ok) throw new Error(`Agent exited with ${result.exitCode}`);
111
+ await writeFile('hello-from-agent.py', await session.downloadFile('/workspace/hello.py'));
112
+ } finally {
113
+ const cleanup = await vm.terminate();
114
+ if (cleanup.failures.length || cleanup.undeleted.length) {
115
+ console.error('Cleanup needs attention:', cleanup);
116
+ process.exitCode = 1;
117
+ }
118
+ }
119
+ ```
50
120
 
51
- ## License
121
+ ```sh
122
+ node agent.mjs
123
+ ```
52
124
 
53
- Apache-2.0
125
+ For Codex, prepare the image with `--agent codex`, create the VM with
126
+ `AgentVm.create(region, [{ agent: 'codex' }])`, and prompt `'codex'`.
127
+ Agent images must contain the agent you select. Agents run as UID/GID 1000
128
+ in `/workspace`; `installAccess()` installs a short-lived Bedrock token
129
+ after launch. `AgentVm` enables internet egress for model calls.
130
+
131
+ ## Next steps
132
+
133
+ For a `Sandbox` named `vm` and its `session`:
134
+
135
+ | Need | API |
136
+ | --- | --- |
137
+ | Start a task and poll or stream later | `session.run(argv)` → `ExecHandle` |
138
+ | Read live output as byte streams | `session.spawn(argv)` → `ExecProcess` |
139
+ | Keep the VM awake while an exec runs | `await session.keepAwake({ whileBusy: true })` → `KeepAwake` |
140
+ | Upload input or download results | `session.uploadFile(path, bytes)`, `session.downloadFile(path)` |
141
+ | Transfer a directory | `session.uploadTar(path, tarBytes)`, `session.downloadTar(path)` |
142
+ | Freeze and restore a workspace | `vm.suspend()`, `vm.resume()` |
143
+
144
+ `runSync` returns a Promise: it starts a command, waits, and acknowledges
145
+ its saved output. A nonzero exit is a result, so check `result.ok` or
146
+ `result.exitCode`. Use `{ shell: true }` when passing a shell script string.
147
+ Async library errors expose their `ERR_*` code through `error.cause.message`.
148
+
149
+ Omitting `egress` does not block outbound traffic. For no egress, use
150
+ `egressNetworkConnectors: [vpcConnectorArn]` with a VPC without an internet
151
+ gateway, NAT gateway, or other internet route. `denyEgress` sets advisory proxy variables that
152
+ workloads can bypass. Keep the guest execution role limited to the task's needs.
153
+
154
+ [SDK tutorial](https://laithalsaadoon.github.io/microvms-agentd/learn/tutorial/from-code/)
155
+ · [API reference](https://laithalsaadoon.github.io/microvms-agentd/reference/public-api/)
156
+ · [Source](https://github.com/laithalsaadoon/microvms-agentd) · Apache-2.0