Execute File Processing
ctx_execute_fileRun code against a file's content in a sandbox, returning only the printed output. Analyzes large or structured files without loading raw bytes into conversation memory.
Instructions
Read a file into a sandboxed FILE_CONTENT variable and run code over it. Only what you console.log() enters your conversation — the file bytes stay in the sandbox.
Think-in-Code applied to file-level analysis: Reading the whole file means every byte enters your conversation memory and costs reasoning capacity for the rest of the session. Running code over it here lets you keep the raw bytes out and only the derived answer in. Same principle as ctx_execute, scoped to one named file via the FILE_CONTENT variable.
WHEN:
You want to KNOW SOMETHING ABOUT a file (line count, matches of a pattern, parsed structure, statistical aggregate) without needing to SEE all of it
The file is structured (CSV, JSON, log, code) and a code-level derivation is cheaper than reading verbatim
The file is large enough that reading the full content would burn meaningful conversation memory you need for the actual work
The derivation may itself produce a large output you want recall-by-topic on later — pass an
intentstring; outputs over ~5KB are auto-indexed and only matching sections come back, retrievable via ctx_search
WHEN NOT:
You intend to EDIT the file — use Read so the subsequent Edit can match the exact text
You only need one specific line and you know its offset — Read with offset/limit is the simplest path
The file is small AND you will consume all of it for understanding/editing — Read directly
RETURNS:
Only what your code prints. The FILE_CONTENT variable holds the raw bytes inside the sandbox; nothing else leaves. When intent is set and output exceeds the auto-index threshold, the response carries searchable section titles + previews instead of the raw stdout.
EXAMPLE: ctx_execute_file(path: "huge.log", language: "javascript", code: "const errs = FILE_CONTENT.split('\n').filter(l => /ERROR|FATAL/.test(l)); console.log(${errs.length} error lines); console.log(errs.slice(-5).join('\n'))")
EXAMPLE: ctx_execute_file(path: "data.csv", language: "javascript", code: "const rows = FILE_CONTENT.split('\n'); console.log(rows: ${rows.length - 1}, header: ${rows[0]})")
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Absolute file path or relative to project root | |
| language | Yes | Runtime language | |
| code | Yes | Code to process FILE_CONTENT (file_content in Elixir). Print summary via console.log/print/echo/IO.puts/Console.WriteLine. | |
| timeout | No | Max execution time in ms. When omitted, no server-side timer fires — the MCP host's RPC timeout governs. | |
| intent | No | What you're looking for in the output. When provided and output is large (>5KB), returns only matching sections via BM25 search instead of truncated output. |