/code-execution | Type: Embedded | PCID required: No
Tools
| Tool | Description |
|---|---|
code-execution_execute | Execute JavaScript code in a sandboxed VM with access to MCP tools and file helpers. |
- callTool(serverPath, toolName, toolArgs) — Call any MCP tool via HTTP. DO NOT pass PCID — connection is auto-injected from selection context.
- codeExec.createArtifact(filename, content, fileType) — Create a file (uploads to platform, returns { success, id, url, filename, mimeType, size }). Supported types: csv, txt, json, html, xml, js, ts, md, py. This is a simplified file helper — for full artifact features, use the agent’s write_artifact tool.
- codeExec.readArtifact(identifier) — Read a file by ID, filename, or URL (returns { success, content, size, filename, mimeType }). This is a simplified reader — for advanced features (search, pagination, smartGrepQuery), use the agent’s read_artifact tool after code execution returns.
- console.log/error/warn(…args) — Captured to logs array returned in the response.
- setTimeout/setInterval/clearTimeout/clearInterval — Standard timer functions (cleaned up after execution).
${e.from},${e.subject}).join(‘\n’);
await codeExec.createArtifact(‘emails.csv’, csv, ‘csv’);
// Read an artifact from the conversation:
const data = await codeExec.readArtifact(‘file_abc123’);
console.log(data.content);
// Return result to agent:
return { count: emails.length };
LARGE RESULTS: If the returned value serializes to >200 bytes, an artifact is created automatically and the response includes an artifactId with a truncated preview. The agent can use read_artifact to access the full result.
IMPORTANT — NO UNBOUNDED LOOPS:
- NEVER write while(true), while(hasMore), or open-ended loops that call callTool() repeatedly. Each callTool() is an HTTP round-trip and loops will timeout.
- If a tool doesn’t have a pagination parameter (e.g. “page”), do NOT attempt manual pagination — you will get the same page repeatedly.
- If you need more data than one API call returns, return what you have and tell the user the tool’s page limit was reached.
- Bounded loops (e.g. for(let i=0; i<items.length; i++)) over local data are fine.
- Be suspicious of round numbers (30, 50, 100) — they usually mean you hit a perPage limit, not the actual total.
code-execution_execute
Execute JavaScript code in a sandboxed VM with access to MCP tools and file helpers. Available globals:- callTool(serverPath, toolName, toolArgs) — Call any MCP tool via HTTP. DO NOT pass PCID — connection is auto-injected from selection context.
- codeExec.createArtifact(filename, content, fileType) — Create a file (uploads to platform, returns { success, id, url, filename, mimeType, size }). Supported types: csv, txt, json, html, xml, js, ts, md, py. This is a simplified file helper — for full artifact features, use the agent’s write_artifact tool.
- codeExec.readArtifact(identifier) — Read a file by ID, filename, or URL (returns { success, content, size, filename, mimeType }). This is a simplified reader — for advanced features (search, pagination, smartGrepQuery), use the agent’s read_artifact tool after code execution returns.
- console.log/error/warn(…args) — Captured to logs array returned in the response.
- setTimeout/setInterval/clearTimeout/clearInterval — Standard timer functions (cleaned up after execution).
${e.from},${e.subject}).join(‘\n’);
await codeExec.createArtifact(‘emails.csv’, csv, ‘csv’);
// Read an artifact from the conversation:
const data = await codeExec.readArtifact(‘file_abc123’);
console.log(data.content);
// Return result to agent:
return { count: emails.length };
LARGE RESULTS: If the returned value serializes to >200 bytes, an artifact is created automatically and the response includes an artifactId with a truncated preview. The agent can use read_artifact to access the full result.
IMPORTANT — NO UNBOUNDED LOOPS:
- NEVER write while(true), while(hasMore), or open-ended loops that call callTool() repeatedly. Each callTool() is an HTTP round-trip and loops will timeout.
- If a tool doesn’t have a pagination parameter (e.g. “page”), do NOT attempt manual pagination — you will get the same page repeatedly.
- If you need more data than one API call returns, return what you have and tell the user the tool’s page limit was reached.
- Bounded loops (e.g. for(let i=0; i<items.length; i++)) over local data are fine.
- Be suspicious of round numbers (30, 50, 100) — they usually mean you hit a perPage limit, not the actual total.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
code | string | Yes | — | JavaScript code to execute in the sandbox. |
timeout | number | No | 600000 | Timeout in milliseconds (default: 600000 = 10 minutes, min: 1000 = 1 second, max: 900000 = 15 minutes) |

