code-mode-core
v2.1.2
Published
Platform-agnostic code execution engine. Chains multiple tool calls into a single TypeScript code execution in a secure sandbox.
Maintainers
Readme
code-mode-core
Platform-agnostic engine for code-mode — execute TypeScript code chains with registered tools in a secure V8 sandbox.
This is the core SDK extracted from the n8n-nodes-utcp-codemode community node. Use it to build code-mode integrations for any platform.
Install
npm install code-mode-coreUsage
import { CodeModeEngine } from 'code-mode-core';
const engine = await CodeModeEngine.create();
// Register tool sources (MCP, HTTP, or external tools)
await engine.registerToolSource({
name: 'fs',
call_template_type: 'mcp',
config: {
mcpServers: {
filesystem: {
transport: 'stdio',
command: 'node',
args: ['path/to/server-filesystem/dist/index.js', '/allowed/dir']
}
}
}
});
// Execute code with access to all registered tools
const { result, logs } = await engine.execute(`
const files = fs.filesystem_list_directory({ path: '/tmp' });
return files;
`, { timeout: 30000, memoryLimit: 128 });
await engine.close();Features
- Secure V8 sandbox via isolated-vm
- MCP tool integration — register any MCP server as a tool source
- External tool composition — merge platform tools into the sandbox via
externalToolsAPI - Setup caching — FIFO cache (16 entries) keyed by config hash
- Execution tracing —
enableTracereturnsToolCallRecord[]with timing data - TypeScript interfaces — auto-generated from registered tool schemas
Benchmark
96% token savings on a 5-tool pipeline. See the full benchmark.
Related
- n8n-nodes-utcp-codemode — This engine as an n8n community node
- code-mode-tools — This engine as an MCP server
- Code-First n8n Proving Ground — Full lifecycle thesis with POC workflows
License
MPL-2.0
