code_execute
Execute Python or JavaScript code in a sandbox to test scripts, debug algorithms, or run isolated code snippets safely.
Instructions
Execute Python or JavaScript code in a sandbox ($0.01)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| language | No | python |
Implementation Reference
- index.js:45-45 (registration)Registration of the code_execute tool in the TOOLS array.
{ name: 'code_execute', description: 'Execute Python or JavaScript code in a sandbox', inputSchema: { type: 'object', properties: { code: { type: 'string' }, language: { type: 'string', enum: ['python', 'javascript'], default: 'python' } }, required: ['code'] }, endpoint: '/code/execute', price: '$0.01' }, - index.js:50-79 (handler)Generic callTool function that executes API requests for all tools, including code_execute.
async function callTool(endpoint, params) { const fetch = (await import('node-fetch')).default; const isGet = ['GET'].includes((TOOLS.find(t => t.endpoint === endpoint) || {}).method); const url = isGet ? `${BASE_URL}${endpoint}?${new URLSearchParams(params)}` : `${BASE_URL}${endpoint}`; const res = await fetch(url, { method: isGet ? 'GET' : 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${API_KEY}`, }, body: isGet ? undefined : JSON.stringify(params), }); const text = await res.text(); let data; try { data = JSON.parse(text); } catch { data = { raw: text }; } if (!res.ok) { if (res.status === 402) { throw new Error(`Insufficient credits. Add credits at https://iteratools.com. Cost: ${TOOLS.find(t=>t.endpoint===endpoint)?.price || 'see docs'}`); } throw new Error(`API error ${res.status}: ${text.substring(0, 200)}`); } return data; }