The model is given an 'execute code' tool (usually via tool/function calling). When a task needs computation, it generates code (most often Python) that is sent to an isolated environment (a sandbox: a container/VM with CPU/RAM/time limits and network control). The environment runs the code, captures stdout, errors and artifacts (files, plots), and returns them to the model. The model interprets the result: if there was an error it fixes the code and retries (an iterative loop), and on success it uses the result in its answer. State (variables, uploaded files) can persist across calls within a single session.
LLMs are unreliable at precise computation (arithmetic, data processing, file manipulation) and lack a deterministic runtime. Code Execution solves this by delegating such tasks to an actual interpreter and returning a verified result.
The model that produces code (usually Python) to accomplish the task.
An isolated container/VM with resource limits and network control that runs the model's code.
Official
Captures stdout, errors and files/plots and returns them to the model.
Official
Code comes from the model and may be malicious or buggy; without isolation it risks compromising the host.
Infinite loops, memory exhaustion, attempts to break out of isolation.
Missing packages, differing library versions or randomness yield unstable results.
Large or sensitive outputs appended to context raise cost and risk.
Models generate code whose execution yields the answer, improving math accuracy.
Mass availability of code execution in an assistant: data analysis, files, charts.
Open environments emerge for safely running LLM-generated code.
Code execution becomes a standard API tool across leading providers and a foundation for coding agents.
Time complexity: O(kod). Space complexity: O(stan_sesji + artefakty).
The language and runtime for code execution.
Whether the sandbox has internet access.
CPU, memory and execution-time limits.
Code is run only when the task requires it (the model's decision).
Many independent sandboxes/calls can run in parallel; a single generate->execute->fix loop is sequential.
Code (e.g. data analysis) runs on CPU in containers/VMs.
A hardware-agnostic pattern; depends on the sandbox environment.