Skip to content

Commit 7ed38b2

Browse files
committed
fix: sync README code example with updated landing page hero
1 parent 7eb0b0b commit 7ed38b2

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,37 @@ npm install secure-exec
1313
Expose secure-exec as a tool with the Vercel AI SDK. Your agent can execute arbitrary code without risking your infrastructure.
1414

1515
```typescript
16-
import { generateText, tool } from "ai";
16+
import { generateText, stepCountIs, tool } from "ai";
1717
import { anthropic } from "@ai-sdk/anthropic";
1818
import { NodeRuntime, createNodeDriver, createNodeRuntimeDriverFactory } from "secure-exec";
1919
import { z } from "zod";
2020

2121
const runtime = new NodeRuntime({
22-
systemDriver: createNodeDriver({ permissions: { fs: true, network: true } }),
22+
systemDriver: createNodeDriver({
23+
permissions: {
24+
fs: () => ({ allow: true }),
25+
network: () => ({ allow: true }),
26+
},
27+
}),
2328
runtimeDriverFactory: createNodeRuntimeDriverFactory(),
2429
memoryLimit: 64,
2530
cpuTimeLimitMs: 5000,
2631
});
2732

28-
const result = await generateText({
29-
model: anthropic("claude-sonnet-4-20250514"),
33+
const { text } = await generateText({
34+
model: anthropic("claude-sonnet-4-6"),
35+
prompt: "Calculate the first 20 fibonacci numbers",
36+
stopWhen: stepCountIs(5),
3037
tools: {
3138
execute: tool({
32-
description: "Run JavaScript in a secure sandbox",
33-
parameters: z.object({ code: z.string() }),
34-
execute: async ({ code }) => {
35-
const logs: string[] = [];
36-
const res = await runtime.exec(code, {
37-
onStdio: (e) => logs.push(e.message),
38-
});
39-
return { exitCode: res.code, output: logs.join("\n") };
40-
},
39+
description: "Run JavaScript in a secure sandbox. Assign the result to module.exports to return data.",
40+
inputSchema: z.object({ code: z.string() }),
41+
execute: async ({ code }) => runtime.run(code),
4142
}),
4243
},
43-
prompt: "Calculate the first 20 fibonacci numbers",
4444
});
45+
46+
console.log(text);
4547
```
4648

4749
## Why Secure Exec

0 commit comments

Comments
 (0)