Passer au contenu principal
OpenAI

11 mars 2026

Ingénierie

From model to agent: Equipping the Responses API with a computer environment

By Bo Xu, Danny Zhang, and Rohit Arunachalam

Chargement…

We're currently in a shift from using models, which excel at particular tasks, to using agents capable of handling complex workflows. By prompting models, you can only access trained intelligence. However, giving the model a computer environment can achieve a much wider range of use cases, like running services, requesting data from APIs, or generating more useful artifacts like spreadsheets or reports.

A few practical problems emerge when you try to build agents: where to put intermediate files, how to avoid pasting large tables into a prompt, how to give the workflow network access without creating a security headache, and how to handle timeouts and retries without building a workflow system yourself.

Instead of putting it on developers to build their own execution environments, we built the necessary components to equip the Responses API(s'ouvre dans une nouvelle fenêtre) with a computer environment to reliably execute real-world tasks.

OpenAI’s Responses API, together with the shell tool and a hosted container workspace, is designed to address these practical problems. The model proposes steps and commands; the platform runs them in an isolated environment with a filesystem for inputs and outputs, optional structured storage (like SQLite), and restricted network access. 

In this post, we’ll break down how we built a computer environment for agents and share some early lessons on how to use it for faster, more repeatable, and safer production workflows.

The shell tool

A good agent workflow starts with a tight execution loop: the model proposes an action like reading files or fetching data with API, the platform runs it, and the result feeds into the next step. We’ll start with the shell tool—the simplest way to see this loop in action—and then cover the container workspace, networking, reusable skills, and context compaction.

To understand the shell tool, it’s first useful to understand how a language model uses tools in general: to do things like call a function or interact with a computer. During training, a model is shown examples of how tools are used and the resulting effects, step by step. This helps the model learn to decide when to use a tool and how to use it. When we say “using a tool”, we mean the model actually only proposes a tool call. It can't execute the call on its own.

L’outil shell est « juste un autre outil » avec diagramme

The shell tool makes the model dramatically more powerful: it interacts with a computer through the command line to carry out a wide range of tasks, from searching for text to sending API requests on your computer. Built on familiar Unix tooling, our shell tool can do anything you'd expect, with utilities like grep, curl, and awk available out of the box.

Compared to our existing code interpreter, which only executes Python, the shell tool enables a much wider range of use cases, like running Go or Java programs or starting a NodeJS server. This flexibility lets the model fulfill complex agentic tasks.

Orchestrating the agent loop

On its own, a model can only propose shell commands, but how are these commands executed? We need an orchestrator to get model output, invoke tools, and pass the tool response back to the model in a loop, until the task is complete.

The Responses API is how developers interact with OpenAI models. When used with custom tools, the Responses API yields control back to the client, and the client requires its own harness for running the tools. However, this API can also orchestrate between the model and hosted tools out of the box. 

When the Responses API receives a prompt, it assembles model context: user prompt, prior conversation state, and tool instructions. For shell execution to work, the prompt must mention using the shell tool and the selected model must be trained to propose shell commands—models GPT‑5.2 and later are trained for this. With all of this context, the model then decides the next action. If it chooses shell execution, it returns one or more shell commands to Responses API service. The API service forwards those commands to the container runtime, streams back shell output, and feeds it to the model in the next request’s context. The model can then inspect the results, issue follow-up commands, or produce a final answer. The Responses API repeats this loop until the model returns a completion without additional shell commands.

Diagramme de la boucle agent : l’API Responses orchestre le modèle et l’exécution des commandes shell dans un conteneur

When the Responses API executes a shell command, it maintains a streaming connection to the container service. As output is produced, the API relays it to the model in near real time so the model can decide whether to wait for more output, run another command, or move on to a final response.

Sortie d’exécution de commande shell en continu

L’API Responses diffuse en continu la sortie des commandes shell

The model can propose multiple shell commands in one step, and the Responses API can execute them concurrently using separate container sessions. Each session streams output independently, and the API multiplexes those streams back into structured tool outputs as context. In other words, the agent loop can parallelize work, such as searching files, fetching data, and validating intermediate results.

L’API Responses multiplexe les sessions d’exécution des commandes

When the command involves file operations or data processing, shell output can become very large and consume context budgets without adding useful signals. To control this, the model specifies an output cap per command. The Responses API enforces that cap and returns a bounded result that preserves both the beginning and end of the output, while marking omitted content. For example, you might bound the output to 1,000 characters, with preserved beginning and end:

text at the beginning ... 1000 chars truncated ... text at the end

Together, concurrent execution and bounded output make the agent loop both fast and context-efficient so the model can keep reasoning over relevant results instead of getting overwhelmed by raw terminal logs.

When the context window gets full: compaction

One potential issue with agent loops is that tasks can run for a long time. Long-running tasks fill the context window, which is important for providing context across turns and across agents. Picture an agent calling a skill, getting a response, adding tool calls and reasoning summaries—the limited context window quickly fills up. To avoid losing the important context as the agent continues running, we need a way to keep the key details and remove anything extraneous. Instead of requiring developers to design and maintain custom summarization or state-carrying systems, we added native compaction in the Responses API, designed to align with how the model behaves and how it's been trained.

Our latest models are trained to analyze prior conversation state and produce a compaction item that preserves key prior state in an encrypted token-efficient representation. After compaction, the next context window consists of this compaction item and high-value portions of the earlier window. This allows workflows to continue coherently across window boundaries, even in extended multi-step and tool-driven sessions. Codex relies on this mechanism to sustain long-running coding tasks and iterative tool execution without degrading quality.

Compaction is available either built-in on the server or through a standalone `/compact` endpoint. Server-side compaction lets you configure a threshold, and the system handles compaction timing automatically, eliminating the need for complex client-side logic. It allows a slightly larger effective input context window to tolerate small overages right before compaction, so requests near the limit can still be processed and compacted rather than rejected. As model training evolves, the native compaction solution evolves with it for every OpenAI model release.

Codex helped us build the compaction system while serving as an early user of it. When one Codex instance hit a compaction error, we'd spin up a second instance to investigate. The result was that Codex got a native, effective compaction system just by working on the problem. This ability for Codex to inspect and refine itself has become an especially interesting part of working at OpenAI. Most tools only require the user to learn how to use them; Codex learns alongside us.

Container context

Now let’s cover state and resources. The container is not only a place to run commands but also the working context for the model. Inside the container, the model can read files, query databases, and access external systems under network policy controls.

Un diagramme montrant l’intérieur du conteneur d’exécution : fichiers, bases de données, compétences et un réseau contrôlé par des politiques

File systems

The first part of container context is the file system for uploading, organizing, and managing resources. We built container and file(s'ouvre dans une nouvelle fenêtre) APIs to give the model a map of available data and help it choose targeted file operations instead of performing broad, noisy scans.

A common anti-pattern is packing all input directly into prompt context. As inputs grow, overfilling the prompt becomes expensive and hard for the model to navigate. A better pattern is to stage resources in the container file system and let the model decide what to open, parse, or transform with shell commands. Much like humans, models work better with organized information.

Databases

The second part of container context is databases. In many cases, we suggest developers store structured data in databases as SQLite and query them. Instead of copying an entire spreadsheet into the prompt, for example, you can give the model a description of the tables—what columns exist and what they mean—and let it pull the rows it needs.

For example, if you ask, “Which products had declining sales this quarter?” the model can query just the relevant rows instead of scanning the whole spreadsheet. This is faster, cheaper, more scalable to larger datasets.

Accès réseau 

La troisième composante du contexte du conteneur est l’accès réseau, un élément essentiel des charges de travail des agents. Le flux de travail de l’agent peut nécessiter de récupérer des données en temps réel, d’appeler des API externes ou d’installer des packages. En parallèle, donner aux conteneurs un accès internet sans restriction peut être risqué : cela peut exposer des informations à des sites externes, interagir involontairement avec des systèmes internes ou tiers sensibles, ou rendre plus difficiles la prévention des fuites d’identifiants et de l’exfiltration de données.

Pour répondre à ces préoccupations sans limiter l’utilité des agents, nous avons développé des conteneurs hébergés afin d’utiliser un proxy de sortie sidecar. Toutes les requêtes réseau sortantes passent par un niveau de politiques centralisée qui applique des listes d’autorisation et des contrôles d’accès tout en rendant le trafic observable. Pour les identifiants, nous utilisons une injection de secrets au niveau de la sortie, limitée par domaine. Le modèle et le conteneur ne voient que des variables de substitution, tandis que les valeurs réelles des secrets restent hors du contexte visible par le modèle et ne sont appliquées que pour des destinations approuvées. Cela réduit le risque de fuite tout en continuant à permettre des appels externes authentifiés.

Diagramme de l’accès réseau contrôlé via un proxy de sortie : configuration du conteneur

Compétences d’agent

Les commandes shell sont puissantes, mais de nombreuses tâches suivent des schémas multi-étapes récurrents. Les agents doivent redécouvrir le flux de travail à chaque exécution—en replanifiant, en relançant les commandes et en réapprenant les conventions—ce qui entraîne des résultats incohérents et du temps d’exécution perdu. Compétences d’agent(s'ouvre dans une nouvelle fenêtre) regroupe ces schémas en blocs réutilisables et composables. Concrètement, une compétence est un ensemble de dossiers qui inclut ‘SKILL.md(s'ouvre dans une nouvelle fenêtre)' (contenant des métadonnées et des instructions) ainsi que toutes les ressources d’appui, telles que des spécifications d’API et des ressources d’interface utilisateur.

Cette structure correspond naturellement à l’architecture d’exécution que nous avons décrite précédemment. Le conteneur fournit des fichiers persistants et un contexte d’exécution, et l’outil shell fournit l’interface d’exécution. Avec ces deux éléments en place, le modèle peut découvrir les fichiers de compétences via des commandes shell (ls, cat, etc.) lorsque nécessaire, interpréter les instructions et exécuter les scripts de compétences au sein d’une même boucle agent.

Nous fournissons des API(s'ouvre dans une nouvelle fenêtre) pour gérer les compétences sur la plateforme OpenAI. Les développeurs importent et stockent des dossiers de compétences sous forme de paquets versionnés, qui peuvent ensuite être récupérés via un identifiant de compétence. Avant d’envoyer l'invite au modèle, API Responses charge la compétence et l’inclut dans le contexte du modèle. Cette séquence est déterministe :

  1. Récupérer les métadonnées des compétences, y compris le nom et la description.
  2. Récupérez le paquet de compétences, copiez-le dans le conteneur et décompressez-le.
  3. Mettez à jour le contexte du modèle avec les métadonnées des compétences et le chemin d’accès du conteneur.

Lorsqu’il décide si une compétence est pertinente, le modèle explore progressivement ses instructions et exécute ses scripts via des commandes shell dans le conteneur.

Diagramme du pipeline de chargement des compétences : registre, ensemble, environnement d’exécution

Comment les agents sont créés

Pour rassembler tous les éléments : l’API Responses assure l’orchestration, l’outil shell fournit des actions exécutables, le conteneur hébergé fournit un contexte d’exécution persistant, les compétences apportent une logique de flux de travail réutilisable, et le compactage permet à un agent de fonctionner sur une longue durée avec le contexte dont il a besoin.

Avec ces primitives, une seule invite peut s’étendre en un flux de travail de bout en bout : découvrir la bonne compétence, récupérer des données, les transformer en un état structuré local, les interroger efficacement et générer des artefacts durables. 

Le diagramme ci-dessous montre comment ce système fonctionne pour créer une feuille de calcul à partir de données en direct.

Diagramme du cycle de vie des requêtes : d’une invite à des artefacts durables, découverte des compétences

L’API Responses orchestre une tâche agentive

Créer votre propre agent

Pour un exemple détaillé combinant l’outil shell et l’environnement informatique dans des flux de travail de bout en bout, consultez notre article de blogue développeur(s'ouvre dans une nouvelle fenêtre) ainsi que le cookbook(s'ouvre dans une nouvelle fenêtre), qui expliquent comment préparer une compétence et l’exécuter via l’API Responses.

Nous avons hâte de voir ce que les développeurs vont créer avec cet ensemble de primitives. Les modèles de langage ne sont pas conçus uniquement pour générer du texte, des images et de l’audio—nous continuerons à faire évoluer notre plateforme pour la rendre plus performante dans la gestion de tâches complexes, concrètes et à grande échelle.

Auteur

Bo Xu, Danny Zhang, Rohit Arunachalam