Code interpreter
A code interpreter is a tool that lets a language model run the code it writes and read back what that code produced.
A code interpreter is a tool that runs code written by a language model and returns what the code printed or produced. The model sends the code as a tool call, most often in Python, and gets the output back as the result. If the code fails, the error message comes back instead, and the model can fix the code and try again. Files the code writes, such as a chart or a cleaned dataset, can be handed back as well.
Language models are unreliable at exact arithmetic and at handling large amounts of data in their own text. Code does both reliably, so a model that can run code can answer questions it could not answer by writing alone. A model can also check its own work, by running a test or comparing a result against the data. Many chat assistants offer a code interpreter for data analysis, where a user uploads a file and the model explores it with code.
The code runs in a sandbox, because it is untrusted code that no one reviews before it runs. Each user or conversation usually gets its own sandbox, which keeps one session from reading the files of another. The sandbox stays up between calls for as long as the session lasts, and it keeps its memory while the model is thinking. An idle session is usually shut down after a timeout, and its state is lost unless it was saved.