English
TypeScript Code Sandbox (PTC)
ptc (Programmatic Tool Calling) is a built-in tool that lets the model execute short, sandboxed TypeScript or JavaScript snippets inside Node 24.
Unlike MCP—which defines how iKi connects to external services—ptc is an execution environment. It can orchestrate both built-in tools (such as tools.bash) and any connected MCP server (mcp.<server>.<tool>) inside a single turn.
Why Use a Code Sandbox
When a task requires looping, parallel requests, or filtering large payloads, sequential tool calls waste round-trips and fill conversation history with raw intermediate data.
Inside ptc, the model can combine multiple steps into one script. For example, combining Zotero MCP calls with local workspace checks:
typescript
// 1. Search Zotero for papers matching a topic
const hits = await mcp.zotero.zotero_search_items({
query: 'KV-Cache',
limit: 5,
});
const keys: string[] = hits.data?.items?.map((item: { key: string }) => item.key) ?? [];
// 2. Fetch PDF annotations in parallel and export BibTeX
const [annotations, bib] = await Promise.all([
Promise.all(keys.map(key => mcp.zotero.zotero_get_annotations({ item_key: key, format: 'json' }))),
mcp.zotero.zotero_export_bibliography({ item_keys: keys, export_format: 'bibtex' }),
]);
// 3. Return only the distilled summary to the model context
return {
matched: keys.length,
highlights: annotations.flatMap(res => res.data ?? []).slice(0, 20),
bibtex: bib.text,
};Sandbox Globals
Scripts run with the following globals:
| Global | Purpose |
|---|---|
mcp.servers() | List connected MCP servers and their tool counts |
mcp.describe(server, tool?) | Inspect generated TypeScript declarations on demand |
mcp.<server>.<tool>(args) | Call an MCP tool and receive normalized { content, text, data?, isError? } |
tools.list() / tools.<name>(args) | Call built-in tools (for example await tools.bash({ command: 'git status -s' })) |
workspace, console, sleep(ms) | Current workspace path, captured logs, and async delay |
Isolation & Guardrails
- Isolated
node:vmcontext: TypeScript is stripped natively by Node 24;process,fs,require,eval, andnew Functionare unavailable. - No recursion:
ptccannot invokeptc. - Bounded execution: Tool call counts, execution time, and returned output bytes are all capped.
Configuration
Tune sandbox limits in ~/.iki/settings.toml:
toml
[tools.ptc]
enabled = true
defaultTimeoutMs = 30000
maxTimeoutMs = 120000
maxToolCalls = 32
maxOutputBytes = 32768