Skip to main content
Glama

Execute JS Code (Sandbox)

mj_execute_code

Execute JavaScript in a secure sandbox to automate Memory Journal MCP tool calls, inspect schemas, and pass context data for journal, search, and update workflows.

Instructions

Run arbitrary JavaScript to automate tasks in a secure sandbox. IMPORTANT: You MUST use the mj object (NOT api, journal, or mcp) to access tools. DO NOT use import() or require(); the mj tools are globally available in the sandbox. Available tools are mapped directly from MCP tool names, converted to camelCase (e.g., create_entry -> mj.createEntry(), search_entries -> mj.searchEntries()). Anti-Hallucination Hint: DO NOT GUESS parameter keys (e.g., passing repo instead of repo_name will fail). ALWAYS inspect the schema first if unsure: return await mj.createEntry.schema(). Execution limit: 30s. Network access (fetch) disabled. Example: return await mj.searchEntries({ query: "PowerShell" })

Input Schema

NameRequiredDescriptionDefault
codeNoREQUIRED string parameter containing JavaScript code to execute inside the sandbox. Uses the `mj` global object for API access (e.g. `return await mj.core.getRecentEntries({ limit: 10 })` or `return await mj.core.createEntry(context.entry)`). Anti-Hallucination Hint: Code Mode executes valid JavaScript (e.g., `return await mj.core.getRecentEntries({ limit: 10 })`), NOT raw SQL queries (e.g. `SELECT * FROM journal_entries`) or direct SQLite prepared statements (e.g. `const db = mj.getDatabase(); db.prepare(...)`). When querying or searching, use `mj.core.getRecentEntries({ limit: 10 })` or `mj.search.searchEntries({ query: "..." })`. To update entries, use `mj.admin.updateEntry({ entry_id: ..., content: ... })` instead of raw SQL UPDATE statements. DO NOT call with an empty payload `{}` or pass entry/query payloads directly without including the `code` parameter. When passing markdown or strings with nested backticks, single quotes, or double quotes, pass them safely via the `context` parameter (e.g., `mj.createEntry({ ...context.entry })` or `context.content`) to avoid double-escaping errors that prematurely terminate string literals, or ensure nested characters are escaped cleanly. Node.js native modules (`fs`, `path`, `child_process`, `require()`, `import`) are disabled in the sandbox; pass file content or external data using the `context` parameter instead.
repoNoTarget repository name to set as default context for all github/kanban tools executed in this sandbox (e.g., "memory-journal-mcp").
entryNoOptional entry object or dictionary to create/update. When passed without code, Code Mode automatically synthesizes an appropriate journal entry.
queryNoOptional search query string or SQL-style query string. If provided, Code Mode will automatically resolve it to search or retrieve entries.
contextNoA JSON object, string, or array to pass variables directly into the sandbox (accessible via `context` inside JS code). Use this to pass file contents, external text, or complex entry objects into Code Mode without requiring `fs` or dynamic `require()`.
dry_runNoIf true, state-modifying API calls (create_entry, update_entry, etc.) will be skipped, returning simulated success.
payloadNoOptional payload object, dictionary, or JSON string (e.g. { action: "create", task: "...", notes: "...", changes: [...] }). When passed without code, Code Mode automatically translates and synthesizes it into a type-safe journal entry or API execution.
timeoutNoMaximum execution time in milliseconds before the sandbox forcibly terminates the script (max: 30000ms).
readonlyNoIf true, execution is restricted to read-only operations. Write tools will be filtered out of the API bridge.
use_test_dbNo
auto_versionNoAutomatically inject expected_version for optimistic concurrency on updates/deletes
workspace_idNoTarget workspace ID to isolate data. If omitted, uses defaultWorkspaceId if configured.
maxResultSizeNoAlias for max_result_size.
project_numberNoNumeric project ID to bind to all tool calls in this sandbox. Repo name strings (e.g., "mysql-mcp") are auto-resolved via the project registry. Falls back to DEFAULT_PROJECT_NUMBER if unspecified. Find it by querying memory://agent-id.
max_result_sizeNoMaximum allowed result size in bytes (default: 102400 / 100KB, max: 52428800 / 50MB). Pass a higher limit (e.g. 200000 or 524288) when returning large datasets or multi-entry contents to avoid result truncation.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv9.0.0

TDQS

A4.5/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Goes well past the annotations (which only declare openWorld=true, readOnly=false, idempotent=false, destructive=false) by disclosing the 30s execution limit, disabled network access via fetch, and disabled Node modules (fs, path, child_process, require, import). It also warns that guessed parameter keys will fail and points to `.schema()` for inspection, which is exactly the kind of context annotations cannot carry.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the core instruction ('Run arbitrary JavaScript') and then layered with warnings, limits, and a concrete example. Slightly dense in the middle, but every sentence (IMPORTANT, Anti-Hallucination Hint, limits, example) carries actionable information rather than filler.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 15-parameter meta-tool with no output schema and 93% schema coverage, the description covers what an agent actually needs before calling: the sandbox contract, the bridge naming convention, and the hard limits. The remaining gap is that it does not sketch the `mj` API surface (available tool namespaces) beyond two examples, so an agent still needs schema inspection.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is already 93%, so the baseline is 3, but the description adds real meaning on the critical `code` parameter: the camelCase mapping convention (`create_entry` -> `mj.createEntry()`), the schema-inspection escape hatch, and the note that nested quotes should be routed through `context`. No description-level coverage is offered for `dry_run`, `readonly`, or `max_result_size`, leaving those entirely to the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource: 'Run arbitrary JavaScript to automate tasks in a secure sandbox'. It also implicitly distinguishes itself from every sibling by explaining that all other tools are reached through the `mj` bridge rather than called directly, which an agent can act on immediately.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives strong operational context: use `mj`, not `api`/`journal`/`mcp`; no import()/require(); inspect the schema before guessing parameter names. What it lacks is an explicit 'use this when a single call would do otherwise' exclusion, so it stops short of full alternative routing, but the how-to-use guidance is unusually rich.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools