---
title: "Code execution API · sandboxed Python for LLMs in the EU"
description: "Let open models write and run Python in a sandbox with the OpenAI Responses code_interpreter tool. Data analysis, calculations and files, run in the EU."
canonical: "https://inference.eu/api/code-execution/"
language: "en"
---

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.

[Contact sales](https://inference.eu/contact/)[Example request](#example)

1.  01API format: OpenAI
2.  02EU data centres
3.  03Covered by one DPA

POST /v1/responses

```
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

Endpoint

POST /v1/responses

Category

Tools

API format

OpenAI

Base URL

api.inference.eu/v1

Processing

EU data centres

Training on your data

Never

## Code execution: common questions

The questions buyers, developers and legal teams ask us most. Something missing? Ask us directly.

It is a built-in tool that lets the model write and run Python in a sandbox during a request. The model uses it for calculations, data analysis and file processing, then answers with the results. You enable it with \`{"type": "code\_interpreter"}\` in the \`tools\` array of a Responses request.

Yes. The \`code\_interpreter\` tool type, the \`container\` setting with \`file\_ids\`, and the \`code\_interpreter\_call\` output items follow the OpenAI Responses API. Code written for that format works after you change the base URL, key and model.

Upload the file with \`POST /v1/files\` and \`purpose\` set to \`user\_data\`, then pass its id in \`container.file\_ids\`. The model can read the file in Python, analyse it and answer your question, showing the code it used to get each number.

No. By default the sandbox has no network access and is isolated from your systems and from other customers. Code can only work with the files you attach and what it creates itself. If you need the model to fetch data, combine code execution with web search or your own tools.

The sandbox runs Python with common libraries for data work, such as tools for tables, numerical computing and charts. Packages cannot be installed from the internet during a run. If your use case needs a specific library, tell us and we will check what is possible.

Yes. Files the code writes, such as PNG charts or cleaned CSV files, stay in the container and are referenced in the answer as container file citations. Download them from the container before it expires, then store them in your own systems.

Sandboxes run in European data centres. Containers and the files in them are deleted after a period without use, and nothing is used to train models. Delete uploaded input files through the files API when you no longer need them.

Each run has limits on time, memory and file size that depend on your plan, and we confirm them with you. Most analyses of ordinary business files finish well within them. For very large datasets, filter or aggregate the data before you upload it.

[Ask a question](https://inference.eu/contact/)

## Related

[API overview](https://inference.eu/api/)

-   [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](https://inference.eu/api/responses/)
-   [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](https://inference.eu/api/files/)
-   [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](https://inference.eu/api/web-search/)
-   [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](https://inference.eu/api/reasoning/)

## 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
