Python 88.3%
TypeScript 7.6%
Shell 4.1%
1# xAI Code Execution tool (`type: "code_interpreter"`, alias `"code_execution"`)23**Status:** DOCUMENTED · LIVE_VERIFIED (2026-09-19, grok-4.3: `print(2+2)` → `code_interpreter_call` with `code`, `outputs[0].logs` stdout `4`, `code_interpreter_calls: 1`; streamed run emitted the 5 `response.code_interpreter_call*` events; `{type:"code_execution"}` accepted and echoed as `code_interpreter`)4**Sources:** https://docs.x.ai/developers/tools/code-execution · https://docs.x.ai/developers/tools/streaming-and-sync (include values) · https://docs.x.ai/developers/model-capabilities/files/chat-with-files (files + code) · OpenAPI `CodeInterpreterCall`, `CodeInterpreterOutput`5**Last verified:** 2026-09-1967## Parameters8`{"type":"code_interpreter"}` (OpenAI SDK name) or `{"type":"code_execution"}` (xAI name; normalised). `container` accepted for compatibility (not needed). Responses only (gRPC/xai-sdk: `code_execution()`; `code_interpreter` string not supported there).910## Output11```json12{"type":"code_interpreter_call","id":"ci_<resp>_call-…-0","status":"completed","code":"print(2+2)",13 "outputs":[{"type":"logs","logs":"{\"stdout\":\"4\\n\",\"stderr\":\"\",\"exit_code\":0,\"command_timed_out\":false}"}]}14```15`outputs[]` only with `include:["code_interpreter_call.outputs"]` (`logs` is a **JSON string** with stdout/stderr/exit_code/command_timed_out; image outputs `{type:"image", url}`). Chat Completions: generated files via `output_files[]` with `include: code_execution_files_output` (docs; chat has no tools[] support live). Stream: `response.code_interpreter_call.in_progress → …call_code.delta → …call_code.done → …call.interpreting → …call.completed`.1617## Sandbox18Python with NumPy/Pandas/Matplotlib/SciPy; no network, no persistent filesystem, per-request stateless; time/memory limits. Attach data files (`input_file`) to analyse them. Usage live: 2 324 tokens (368 reasoning) + 1 call = ticks 81 834 000 ≈ $0.0082.1920## Billing21$5 per 1k calls + tokens. Docs recommend low temperature for math.2223Examples: `examples/xai/tools/code-execution/`. Test: `tests/xai/test_tools.py::test_code_interpreter_tool` (RUN_EXPENSIVE_TESTS).24