POST /v1/responses
Code execution tool: sandboxed Python for models, run in the EU
Language models are good at writing code and unreliable at mental arithmetic. The code execution tool lets a model write Python, run it in an isolated sandbox and use the result in its answer. It turns questions about spreadsheets, statistics or unit conversions into computed answers instead of estimates. The sandboxes run in European data centres.
- 01API format: OpenAI
- 02EU data centres
- 03Covered by one DPA
curl https://api.inference.eu/v1/responses \
-H "Authorization: Bearer $INFERENCE_EU_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-oss-120b",
"tools": [{
"type": "code_interpreter",
"container": {"type": "auto", "file_ids": ["file-4b81c0"]}
}],
"instructions": "Use Python to analyse the attached CSV. Show the numbers you computed.",
"input": "Which three product categories grew fastest in revenue between Q2 and Q3, and by how much?"
}'What the tool does
Add a tool with type: "code_interpreter" to a POST /v1/responses request. When the model decides that code would help, it writes Python, the API runs it in a sandbox, and the model reads the output, fixes errors if the code fails and runs it again until it has what it needs. Then it answers in text.
Each run appears in output as a code_interpreter_call item with the code the model wrote and the container_id it ran in. Showing that code to users, or logging it, makes the answer checkable: anyone can see how a number was calculated.
Containers and files
The container field sets where code runs. {"type": "auto"} creates a fresh sandbox for the request, or reuses one from earlier turns in the same conversation. Add file_ids to make files available inside it: upload a CSV, Excel file or JSON first with the files API using purpose user_data, then pass its id.
The sandbox has Python with common data libraries for tables, statistics and charts. Files the code creates, such as a cleaned CSV or a chart image, are referenced in the answer as container file citations so you can download them. Containers expire after a period without use, and their files are deleted with them.
Practical patterns
Data analysis: attach an export from your shop, CRM or finance system and ask questions in plain language, such as growth by category or the customers with overdue invoices. Calculations: loan schedules, unit and currency conversions with rates you provide, or tax examples, where exact arithmetic matters. Transformations: clean a messy spreadsheet, merge two files or reshape data into the format another system expects.
Combine it with reasoning models for multi-step analysis, and with structured outputs if a program reads the final figures. For recurring reports, keep the prompt fixed and only change the attached file.
Errors, limits and safety
The sandbox is isolated from your systems and from other customers, and by default it has no access to the internet, so code cannot send data elsewhere or install packages from the network. If code fails, the error is returned to the model, which usually corrects it; persistent failures end with an explanation in the answer.
Runs have limits on time, memory and file size that depend on your plan, and we confirm them with you. Very large files are better summarised or filtered before upload. Check results that matter: the arithmetic is exact, but the model can still choose the wrong column or misread the question.
Code execution: common questions
The questions buyers, developers and legal teams ask us most. Something missing? Ask us directly.
Related
- ResponsesUse the OpenAI Responses API format with open-weight models on inference.eu. Typed output items, built-in tools and multi-turn state, processed in the EU.Endpoints
- FilesUpload, list, download and delete files with an OpenAI-compatible files API. Use them for batch jobs and tools; stored in EU data centres.Endpoints
- Web searchLet open models search the web during a request with the OpenAI Responses web_search tool. Current answers with source citations, run from the EU.Tools
- Reasoning modelsUse open reasoning models that think before they answer. Control reasoning effort, read reasoning tokens and handle limits, processed in EU data centres.Guides
Move your AI workloads to EU infrastructure
Tell us which models you use and roughly how much traffic you have. We reply within one working day with pricing and next steps.
- Reply within one working day
- Pricing for your volume
- DPA ready to sign