Skip to main content

Runtimes

mcp-exec supports three runtimes. Choose based on whether you need MCP tool access, state persistence, or arbitrary Python packages.

Node.jsBashPython
StatePersistent (globalThis)StatelessStateless
MCP accessYes, via importsNoYes, via HTTP bridge
Return valueIIFE returnstdoutstdout
Custom packages6 bundledsystem toolsPEP 723 (any PyPI)
Best forOrchestrationPipelinesData analysis

Node.js​

State: Persistent within a session via globalThis. Data stored between calls is available in subsequent exec calls within the same conversation.

MCP imports: import { tool } from 'mcp/server-name' — async/await, same as any ES module.

Bundled packages (no install step needed): zod, lodash-es, date-fns, csv-parse, cheerio, xlsx

Return value: The last expression of the async IIFE body. Structured values (objects, arrays) are returned as-is.

Best for: MCP orchestration, multi-step workflows, stateful computation, anything that needs to call multiple MCP tools and aggregate results.

exec({
runtime: "node",
code: `
import { searchInvoices, getInvoice } from 'mcp/quickbooks';
import { getCustomer } from 'mcp/crm';
import { createDraft } from 'mcp/gmail';

const overdue = await searchInvoices({ status: 'overdue' });
const details = await Promise.all(
overdue.map(inv => Promise.all([
getInvoice({ id: inv.id }),
getCustomer({ id: inv.customerId })
]))
);
const body = details
.map(([inv, cust]) => \`\${inv.amount} — \${cust.name}\`)
.join('\\n');
await createDraft({ to: 'sales@co.com', subject: 'Overdue invoices', body });
return \`Draft created — \${overdue.length} invoices\`;
`
})
// → "Draft created — 23 invoices"

Codex CLI runtime notes​

When running from Codex CLI, all three runtimes work identically from mcp-exec's perspective.

Codex CLI applies a platform-native sandbox (sandbox-exec on macOS, bwrap on Linux) that wraps the mcp-exec process itself. mcp-exec's srt sandbox wraps code inside exec(). These are independent layers — you get double sandboxing, which is intentional and good.

No special configuration is needed for runtime behavior. Sandbox policy config is the same regardless of whether you're running from Claude Code or Codex CLI — set in settings.json as described in Configuration → Codex CLI.

  • exec() — full parameter reference
  • Sessions — how Node session state works across calls
  • Examples — complete workflows per runtime