Run code over a file (executes code, reads the given path)
ctx_execute_fileRun code over a file inside a sandbox to extract line counts, matches, or aggregates without loading raw bytes into context.
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. Same principle as ctx_execute, scoped to one named file.
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 it would burn conversation memory you need for the actual work
The derivation may itself be large and you want recall-by-topic later — pass
intent; 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 — Read directly
RETURNS: Only what your code prints. FILE_CONTENT holds the raw bytes inside the sandbox; nothing else leaves. Auto-indexed output returns searchable section titles + previews instead of 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'))")
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Code to process FILE_CONTENT (file_content in Elixir). Print summary via console.log/print/echo/IO.puts/Console.WriteLine. | |
| path | Yes | Absolute file path or relative to project root | |
| 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. | |
| language | Yes | Runtime language | |
| timeoutMs | No | Max execution time in MILLISECONDS — timeoutMs: 120000 is two minutes, timeoutMs: 120 is 0.12 seconds. When omitted, the host's own RPC timeout governs where it has one; on hosts that do not bound a call (Pi, Antigravity CLI) a generous server-side default applies instead. |