0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00
mastra/code-mode/isolated-vm
History 2026-10-28 13:15:52 +00:00
..
src Move Code Mode transports into their own top-level folder (#21086) 2026-08-09 08:42:40 -07:00
.gitignore Move Code Mode transports into their own top-level folder (#21086) 2026-08-09 08:42:40 -07:00
CHANGELOG.md chore: version - exit prerelease mode 2026-10-28 13:15:52 +00:00
lint-staged.config.js refactor(lint): replace ESLint with type-aware oxlint (#27476) 2026-10-18 10:38:35 -07:00
package.json chore: version - exit prerelease mode 2026-10-28 13:15:52 +00:00
README.md chore(*): Update/unify/add READMEs (#22858) 2026-09-02 14:36:59 +02:00
tsconfig.build.json Move Code Mode transports into their own top-level folder (#21086) 2026-08-09 08:42:40 -07:00
tsconfig.json Move Code Mode transports into their own top-level folder (#21086) 2026-08-09 08:42:40 -07:00
tsdown.config.ts Move Code Mode transports into their own top-level folder (#21086) 2026-08-09 08:42:40 -07:00
vitest.config.ts Run Code Mode securely in-process without native binaries or Node flags (#21089) 2026-08-09 11:20:39 -07:00

@mastra/isolated-vm

IsolatedVmCodeModeTransport runs model-authored Code Mode programs inside an in-process V8 isolate. Use it when you need a strong execution boundary without starting a separate sandbox process; the isolate has no direct filesystem, network, or process access.

Installation

npm install @mastra/isolated-vm

Usage

On Node.js 20 and later, start the host process with --no-node-snapshot because isolated-vm is a native addon.

import { Agent } from '@mastra/core/agent';
import { createCodeMode, createTool } from '@mastra/core/tools';
import { IsolatedVmCodeModeTransport } from '@mastra/isolated-vm';
import { z } from 'zod';

const getPrice = createTool({
  id: 'getPrice',
  description: 'Get the price of a product',
  inputSchema: z.object({ productId: z.string() }),
  outputSchema: z.object({ price: z.number() }),
  execute: async ({ productId }) => ({ price: productId === 'pro' ? 49 : 19 }),
});

const { tool, instructions } = createCodeMode(
  { tools: { getPrice } },
  new IsolatedVmCodeModeTransport({ memoryLimitMb: 128 }),
);

const agent = new Agent({
  id: 'pricing-agent',
  name: 'Pricing agent',
  instructions: ['Answer pricing questions.', instructions],
  model: 'openai/gpt-5.6-sol',
  tools: { execute_typescript: tool },
});

Documentation

Changelog

See the package changelog for version history and release notes.

Support

We have an open community Discord. Come and say hello and let us know if you have any questions or need any help getting things running.