kosa8 / Integrations / Mastra

Integration · Mastra · Last checked: November 2026

Run Mastra agents in a microVM sandbox

Mastra agents take tools from MCP servers through @mastra/mcp. Point its MCPClient at kosa8, either the local gateway (kosa8 mcp serve) or kosa8 Cloud's MCP server at https://api.kosa8.com/mcp, and the agent gets tools that create sandboxes, run commands and read and write files in microVMs. The Mastra agent itself stays in your Node.js process; the code and commands it asks for run in the sandbox.

01How it works

kosa8 mcp serve speaks the Model Context Protocol over stdio and exposes kosa8's sandboxes, snapshots and forks as typed tools. MCPClient.listTools() returns them named <server>_<tool>, ready to pass to a Mastra Agent. A sandbox an agent creates through the local gateway has no network unless it asks for specific hosts, and can share a folder from your computer only below a directory you allowed with --allow-mount.

kosa8 Cloud's server at https://api.kosa8.com/mcp speaks Streamable HTTP and takes a kosa8 API key as a Bearer token. Its tools include sandbox_create, sandbox_exec, file_read, file_write and sandbox_delete, and the sandboxes run on kosa8's hosts.

02Steps

  1. Install kosa8 and start its daemon. Sandboxes run on an Apple silicon Mac, an x86-64 Linux machine with KVM, or Windows 11 through WSL2 (preview). kosa8 doctor reports anything missing.

  2. Install Mastra and its MCP client. Set your model provider's key in this shell; Mastra calls the model from your process.

  3. Write the agent. The MCP client starts kosa8 mcp serve; the agent gets only the tools whose names start with kosa8_sandbox_.

    agent.mjs
    import { Agent } from '@mastra/core/agent';
    import { MCPClient } from '@mastra/mcp';
     
    const mcp = new MCPClient({
      servers: {
        kosa8: { command: 'kosa8', args: ['mcp', 'serve'], env: { HOME: process.env.HOME, PATH: process.env.PATH } },
      },
    });
     
    // Keep only the sandbox tools: names are <server>_<tool>.
    const all = await mcp.listTools();
    const tools = Object.fromEntries(Object.entries(all).filter(([name]) => name.startsWith('kosa8_sandbox_')));
     
    const coder = new Agent({
      id: 'coder',
      name: 'Coder',
      instructions: 'Run every command in a kosa8 sandbox. Create one with no network, and delete it when you are done.',
      model: 'openai/gpt-5',
      tools,
    });
     
    try {
      const res = await coder.generate('Create a sandbox, write fizzbuzz.py in it, run it for 1..15 and show the output.');
      console.log(res.text);
    } finally {
      await mcp.disconnect();
    }
  4. Run it. Each tool call the model makes goes to the kosa8 gateway and runs in a microVM on this machine.

  5. Or use kosa8 Cloud's MCP server. Swap the server for a URL and a Bearer token. Sandboxes then run on kosa8 Cloud, and nothing on your computer is shared with them.

    agent.mjs
    const mcp = new MCPClient({
      servers: {
        kosa8: {
          url: new URL('https://api.kosa8.com/mcp'),
          requestInit: { headers: { Authorization: `Bearer ${process.env.KOSA8_API_KEY}` } },
        },
      },
    });
  6. Clean up what it left. Locally, list the sandboxes and remove any the agent did not delete.

03Settings

SettingLocal gatewaykosa8 Cloud
Servercommand: 'kosa8', args: ['mcp', 'serve']url: new URL('https://api.kosa8.com/mcp')
Authenticationnone: stdio, as your userAuthorization: Bearer $KOSA8_API_KEY in requestInit
Where sandboxes runthis computerkosa8 Cloud
Network of a new sandboxnone, unless the agent asks for specific hostsyour organization's egress policy
Your foldersonly below --allow-mount DIR, read-only unless DIR:rwnone
Tool names in Mastrakosa8_sandbox_create, kosa8_sandbox_shell, kosa8_sandbox_file_write, ...kosa8_sandbox_create, kosa8_sandbox_exec, kosa8_file_read, ...
Long commandssandbox_exec with background: true, then sandbox_exec_status, for anything over 90 s

04What this protects against, and what it does not

What it protects against

  • Model-written commands and code reaching your computer: they run in a microVM with its own kernel.
  • New sandboxes reaching the internet: on the local gateway they have no network unless the agent names hosts.
  • The agent reading folders you did not allow: only directories below --allow-mount can be shared in.

What it does not

  • Mastra itself, its memory, its other tools and its model calls: they run in your Node.js process.
  • Tools you add from other MCP servers that run on your machine, outside kosa8.
  • What the agent sends to a host it was allowed to reach.

kosa8 limits what a hijacked agent can reach; it does not detect or prevent prompt injection. SOC 2 Type II is in progress; there is no SOC 2 report and no external penetration test yet.

kosa8's TypeScript recipe tested @mastra/mcp 2.4.1 against the local gateway (listing the tools and calling one). The Agent and the kosa8 Cloud configuration on this page follow the published @mastra/mcp 2.11.0 and @mastra/core 1.86.0 types, and were not run with a model for this page.

05Questions

Does the Mastra agent itself run inside the microVM?

No. Mastra runs in your Node.js process and calls the model from there. The commands and file operations it makes through kosa8's MCP tools run in sandboxes, which is where model-written code should run.

What are kosa8's tools called in Mastra?

MCPClient names each tool server_tool, so with a server named kosa8, the local gateway's sandbox_create becomes kosa8_sandbox_create, and kosa8's own kosa8_status becomes kosa8_kosa8_status.

Can sandboxes the agent creates reach the internet?

On the local gateway, a sandbox the agent creates has no network unless the agent asks for specific hosts. On kosa8 Cloud, new sandboxes follow your organization's egress policy.

Can the agent read files on my computer?

Only folders you allow. The local gateway shares a host directory into a sandbox only below a directory given to kosa8 mcp serve with --allow-mount, read-only unless it ends in :rw. kosa8 Cloud sandboxes see nothing from your computer.

Which versions were checked?

kosa8's TypeScript recipe was tested with @mastra/mcp 2.4.1 against the local gateway. The hosted configuration uses MCPClient's url and requestInit options from @mastra/mcp 2.11.0; it was not run for this page.

06Get started

The reference for this page, with every option, is in the kosa8 docs: Mastra.

To try a kosa8 sandbox without installing anything or making an account, kosa8.com/try runs code in a fresh sandbox with no outbound network: 15 minutes of run time free per 24 hours, each run up to 60 s.

Try it free See pricing

Try free with no account. Starter is free with no card; plans from $29 a month.

Last checked: November 2026 · Updated 2026-11-29