假设你正在构建一个代理(Agent),用于回答关于客户上传的 CSV 文件的问题。模型需要运行 Python 代码来获取答案。那么这些代码在哪里运行呢?
一种选择是你自己运行它。这意味着使用 E2B 或 Modal 等沙盒平台,或者你自己的 Docker 容器,同时还要负责将其与你的数据库和互联网隔离开来,限制其运行时间,并修补镜像。
另一种选择是使用服务端代码执行工具。你将该工具添加到 API 请求中,模型决定何时需要运行某些内容,提供商在其自己的沙盒中运行命令,并将输出返回给同一请求中的模型。这里的沙盒指的是一个隔离的 Linux 容器,拥有独立的文件系统、时间限制,并且默认情况下没有网络访问权限。
本文介绍了四个今天提供服务端代码执行的提供商,每个沙盒能做什么和不能做什么,它们在延迟和金钱方面的成本,以及哪些工作仍然需要你自己运营沙盒。
简而言之
服务端代码执行工具在你的 API 请求期间,在提供商的沙盒中运行模型的命令。你无需配置、修补或保护容器。
OpenAI、Anthropic 和 Google 分别为自己的模型运行代码。我们的 openrouter:shell 工具在 Responses 和 Messages API 上为任何模型运行命令,而我们的 openrouter:bash 工具仅在 Messages API 上执行相同操作。这两个工具均处于测试阶段。
我们的沙盒是一个限定于你的账户和工作区的隔离容器,默认关闭出站网络访问,并对每个命令的运行时间和输出大小设置限制。新容器或休眠容器的沙盒时间按每秒 0.0001 美元计费,最低计费时间为 30 秒。
对于自定义基础镜像、GPU 工作或持续数小时的会话,你自己运营沙盒平台仍然是正确的选择。
什么是服务端代码执行
通过订阅,你同意接收 OpenRouter 通讯:模型使用数据、产品更新和研究报道,大约每周一封电子邮件。您可以通过每封电子邮件中的链接随时取消订阅。请参阅我们的隐私政策。
模型本身从不运行任何内容。当它调用工具时,它会发出一个命名该工具和参数的请求,必须有人来执行该操作。对于客户端工具,这个“某人”是你的应用程序代码或你构建的代理框架。你的应用程序接收调用,运行它,并在后续请求中将结果发送回去。对于服务端工具,提供商在其自己的基础设施上运行该调用,并将结果返回给同一请求中的模型,因此你的应用程序没有处理程序。服务端代码执行是第二种类型。
你可能已经在使用以这种方式工作的工具。网络搜索让模型可以在实时网络上查找某些内容,而网页抓取让它读取 URL 的内容。在这两种情况下,你只需在请求中添加一个条目,提供商完成其余工作。代码执行将相同的模式应用于运行命令。
以下步骤适用于任何服务端代码执行工具。当出现字段名称时,指的是我们的 shell 工具使用的名称。
你在请求的 tools 数组中包含该工具。
模型决定需要运行某些内容并发出一个携带一个或多个 shell 命令的调用。
提供商在沙盒容器内按顺序运行这些命令。
每个命令的标准输出、标准错误和结果返回给模型。结果要么是退出代码,要么是超时。
模型读取结果,要么回答你,要么在同一请求中运行更多命令。
步骤二到五重复,直到模型回答。模型运行某些内容,读取输出,决定是否需要另一个命令,然后再次执行。这个循环是代码执行工具赢得其地位的地方,因为模型可以根据实际输出检查结果,而不是猜测。
我们限制了该循环。max_tool_calls 字段设置了一个请求可以采取多少步服务端工具步骤。我们的服务端工具参考将默认值和最大值都设为 30。
托管沙箱与你自行运行的沙箱有何不同
运行你自己的沙箱意味着拥有原本由提供商拥有的部分。你选择基础镜像,配置计算资源,接入 SDK 以启动运行并读取输出,并管理每次运行的生命周期。你还拥有安全边界。
托管工具用 JSON 数组中的一个条目换取了这种控制权。你无需调整容器大小、修补它或操作它。我们构建 openrouter:shell 是为了应对每个请求仅包含少量短命令的场景。
目前谁提供托管代码执行
本文涵盖 OpenAI、Anthropic、Google 和 OpenRouter。Agent SDK 和专用沙箱平台属于不同的类别,将在本文稍后部分介绍。这四大提供商的区别在于它们为哪些模型运行代码。
OpenAI 为 OpenAI 模型运行托管 Shell
OpenAI 的 shell 工具在 OpenAI 管理的容器中运行命令,通过 Responses API 实现。OpenAI 将托管运行时文档化为 Debian 12,默认工作目录为 /mnt/data 。命令以非 sudo 方式运行,不支持交互式 TTY 会话。文档中列出的预装语言包括 Python 3.11、Node.js 22.16、Java 17、PHP 8.2、Ruby 3.1 和 Go 1.23。
托管容器默认没有出站网络访问权限。要启用它,组织管理员在 OpenAI 仪表板中配置白名单,并在请求中的容器环境中设置 network_policy 。通过传递其 id 到 container_reference 环境,可以在不同请求间重用容器,其过期时间是在创建容器时设定的。OpenAI 还有一个单独的 Python 代码解释器工具。
Anthropic 为 Claude 模型运行 Python 和 Bash
Anthropic 的代码执行工具在 Anthropic 管理的沙箱中运行 Python 和 Bash,通过 Messages API 实现。文档描述的环境是一个 Linux x86_64 容器,配备 Python 3.11、5 GiB 内存、5 GiB 工作区存储和一个 CPU。互联网访问被禁用,不允许任何出站连接,因此 Claude 只能使用预装的库,无法在运行期间安装包。
存在三个工具版本,每个支持的模型都接受所有三个版本。code_execution_20250825 支持 Bash 命令和文件操作。code_execution_20260120 增加了跨请求持久化的 Python 解释器状态,这依赖于 Anthropic 的程序化工具调用,在 Claude Haiku 4.5 上不可用。容器在创建后 30 天过期。大约 5 分钟无活动后,容器会被检查点保存,在 30 天窗口内使用其 id 的请求可以恢复它。
Google 为 Gemini 模型运行 Python
Google 的代码执行工具在 Google 管理的沙箱中运行 Python,通过在请求的 tools 中添加 code_execution 条目来启用。文档指出,模型只能生成和执行 Python,代码环境的最大运行时间为 30 秒,且不能安装自己的库。Google 发布了该环境包含的库列表。
我们为任何模型运行托管 Shell
上述三个工具各自仅适用于一家公司的模型。我们的工具适用于 Responses API 和 Messages API 上的任何模型,因为我们在路由层而非单个模型提供商内部运行沙箱。
我们提供两种代码执行工具。openrouter:shell 镜像了 OpenAI 托管 shell 工具的形态,并兼容 Responses API 和 Messages API。openrouter:bash 镜像了 Anthropic bash 工具的形态,仅兼容 Messages API。
这两个工具均处于测试阶段,因此 API 可能会发生变化。沙盒化执行仅在全局 openrouter.ai 端点上运行。区域端点不提供 shell 工具,Chat Completions 会拒绝这两种工具并返回 400 错误,指明支持它们的 API。
将任一工具的引擎设置为 openrouter,命令即可在我们的沙箱中运行。默认引擎为 auto 。对于 openrouter:shell,auto 会保留提供商的原生托管 shell(如果存在),否则路由至我们的沙箱。对于 openrouter:bash,auto 会将工具调用返回给您的应用程序以在客户端运行,我们的服务器上不会执行任何操作。
在我们的沙箱中运行命令
以下是一个完整的请求示例,它运行两个命令并读取返回的结果。
import os
import requests
response = requests.post(
"https://openrouter.ai/api/v1/responses" ,
headers = { "Authorization" : f "Bearer { os.environ[ 'OPENROUTER_API_KEY' ] } " },
json = {
"model" : "anthropic/claude-sonnet-4.5" ,
"input" : "Run cat /etc/os-release and python3 --version, then tell me the OS and Python version in one sentence." ,
"tools" : [
{ "type" : "openrouter:shell" , "parameters" : { "engine" : "openrouter" }}
],
},
)
for item in response.json()[ "output" ]:
if item[ "type" ] == "openrouter:shell" :
print (item[ "container_id" ], item[ "action" ][ "commands" ])
for result in item[ "output" ]:
print (result[ "stdout" ], result[ "outcome" ])
我们在 2026 年 9 月 22 日运行了此请求。模型在一个 shell 调用中发送了两个命令,每个命令都返回了其各自的结果。完整的 os-release 输出包含多行,此处仅截取了前两行。
{
"type" : "openrouter:shell" ,
"container_id" : "sess_art10-418b8597e044" ,
"action" : { "commands" : [ "cat /etc/os-release" , "python3 --version" ] },
"output" : [
{
"stdout" : "PRETTY_NAME= \" Ubuntu 22.04.5 LTS \"\n NAME= \" Ubuntu \"\n " ,
"stderr" : "" ,
"outcome" : { "type" : "exit" , "exit_code" : 0 }
},
{
"stdout" : "Python 3.11.14" ,
"stderr" : "" ,
"outcome" : { "type" : "exit" , "exit_code" : 0 }
}
]
}
沙箱报告称,在该日期 Ubuntu 22.04.5 LTS 搭载 Python 3.11.14。运行时镜像可能会发生变化,因此请从容器中读取版本信息,而不要硬编码。服务器工具参考文档涵盖了其余参数。
封装沙箱的 Agent SDK
如果您基于 Agent SDK 构建应用,而非直接调用 API,某些 SDK 会封装上述工具之一。
OpenAI Agents SDK 提供了 CodeInterpreterTool,它在 OpenAI 的沙箱中运行代码;以及 ShellTool,它根据您配置的环境,在本地运行时或 OpenAI 托管的容器中运行。在假设命令在远程运行的情况下,请先检查您配置的模式。在我们这边,openrouter:shell 是工具数组中的一个条目,与其他任何条目一样,它进入 OpenRouter Agent SDK 循环的方式与进入原始请求的方式相同。
仍需要自有沙箱的场景
托管工具适合简短、有限范围的工作,例如运行脚本、转换文件或检查结果。任何需要特定基础镜像或 GPU 的任务都超出了所有四种托管工具的范围,需要您自行运营沙箱平台。
比较
每个托管工具单元格的内容均源自上述链接的供应商官方文档,OpenRouter 运行时单元格除外,该单元格是我们运行上述请求时沙箱报告的内容。“自管理”列描述的是您自行运行的沙箱,而非任何特定平台。
| OpenRouter | OpenAI | Anthropic | Self-managed (自管理) | ||
|---|---|---|---|---|---|
| 谁在运行 | 我们 | OpenAI | Anthropic | 您 | |
| 模型 | Responses 和 Messages API 上的任何模型 | OpenAI 模型 | Claude 模型 | Gemini 模型 | 任何模型 |
| APIs | Responses 和 Messages。openrouter:bash 仅支持 Messages | Messages | Messages | Gemini API | 任意 |
| 语言 | 任何 shell 命令。2026 年 9 月 22 日报告 Ubuntu 22.04.5 搭载 Python 3.11.14 | Debian 12 上的 Shell 命令。预装 Python、Node.js、Java、PHP、Ruby 和 Go | Python 和 Bash | 仅 Python | 您构建的任何内容 |
文件系统 拥有独立的容器文件系统,范围限定于您的账户和工作区。主目录下的文件在每次命令执行后保存 拥有独立的容器文件系统,默认工作目录为 /mnt/data 。容器过期时数据会被删除 隔离的容器,配备 5 GiB 的工作区存储空间。容器在创建后 30 天过期 未记录 取决于您的镜像和挂载定义
出站网络 默认关闭。允许最多 50 个主机名的白名单,端口为 80 和 443 默认关闭。组织级白名单加上每个请求的 network_policy 禁用 未记录 由您配置
运行时安装包 是,使用白名单中的软件包源 是,使用白名单中的软件包源 否 否 是
会话持久性 通过容器 ID 标识容器。空闲 5 分钟后进入休眠状态。保存的文件在最后使用后保留 30 天 通过 container_reference 按 ID 重用容器。在容器上设置过期时间 在创建后 30 天内按 ID 恢复容器。Interpreter 状态在 code_execution_20260120 及之后版本中,配合程序化工具调用得以保留 每次执行最长运行时间为 30 秒。请求间的状态持久性未记录 最高可达各平台的限制上限
成本模型 推理令牌加上沙盒时间,每秒 $0.0001,新容器或休眠容器的最低计费时间为 30 秒 shell 工具文档中未说明 每个组织每月 1,550 小时免费额度,之后每个容器每小时 $0.05,每次执行最低计费时间为 5 分钟 无额外费用。生成的代码和输出按令牌计费 沙盒运行期间的计算时间
我们的沙盒强制执行的内容
沙盒的意义在于您无需信任模型。您从未打算执行的命令无法访问网络或任何其他容器,并且会在运行的最长时间和输出量上受到硬性限制。本节中的所有内容均描述我们的沙盒机制。上表展示了其他三个方面的差异。
适用于每条命令的限制
我们在隔离的容器中运行每条命令,该容器与您请求的基础设施以及您的机器分离,并限定于您的账户和工作区范围。您可以通过 timeout_ms 设置命令运行的最长时间上限,通过 max_output_length 设置其输出量的上限。timeout_ms 默认为 120,000 毫秒,且不能超过 300,000 毫秒。max_output_length 默认为每个流 16,384 个字符,且不能超过 65,536。包含超过 100 条命令的 shell 调用将被拒绝。
除非您手动开启,否则出站网络访问默认关闭。我们在 2026 年 9 月 22 日进行了验证,发送了一个没有 network_policy 的请求,并让模型使用 curl 获取 https://example.com ,仅打印 HTTP 状态码并在 5 秒后放弃。该命令输出了 000 ,这是 curl 在无响应到达时打印的内容,并以代码 28 退出,这是一个 curl 超时错误。
{ "stdout" : "000" , "stderr" : "curl: (28) Failed to connect to example.com port 443 after 5206 ms: Connection timed out" , "outcome" : { "type" : "exit" , "exit_code" : 28 } }
要开启网络,请设置最多包含 50 个主机名或通配符模式的 network_policy 白名单。仅端口 80 和 443 可达,且该策略在容器启动时即固定。pip install 需要同时在白名单中包含 pypi.org 和 files.pythonhosted.org 。
提示注入以及沙盒的限制
给模型提供 shell 访问权限会使您面临提示注入的风险。如果您的智能体读取网页、支持工单或某人上传的文件,攻击者可以在这些文本中隐藏指令,指示模型忽略您的提示并执行其他操作。
上述限制在模型遵循您的提示或攻击者的指令时同样适用。在注入指令下运行的命令无法访问您配置的网络策略之外的任何主机,而在关闭该策略时则完全无法进行网络访问。它无法访问其他租户的容器,并且会在相同的超时时间内停止。白名单会扩大注入命令能够访问的范围,而 allowed_domains: ["*"] 允许无限制的出站流量,因此请将白名单限制在作业所需的范围内。
您还可以通过请求本身来检测尝试。工作区护栏中的提示注入检测会在将请求转发给模型之前,针对常见注入技术的正则表达式模式检查每个传入请求的用户提供的消息内容。它不会检查此后服务器工具获取的内容,因此模型通过工具读取的页面、文件或命令输出需要您自行进行控制,su
Say you’re building an agent that answers questions about a CSV a customer uploaded. The model needs to run Python to get the answer. Where does that code run?
One option is to run it yourself. That means a sandbox platform such as E2B or Modal , or your own container on Docker, plus the work of keeping it away from your database and the internet, capping its runtime, and patching the image.
A server-side code execution tool is the other option. You add the tool to your API request, the model decides when it needs to run something, and the provider runs the commands in its own sandbox and returns the output to the model inside the same request. A sandbox here means an isolated Linux container with its own filesystem, a time limit, and no network access by default.
This article covers four providers that offer server-side code execution today, what each sandbox can and can’t do, what it costs in latency and money, and the jobs that still need a sandbox you operate yourself.
Tl;dr
A server-side code execution tool runs the model’s commands in the provider’s sandbox during your API request. You don’t provision, patch, or secure a container.
OpenAI, Anthropic, and Google each run code for their own models. Our openrouter:shell tool runs commands for any model on the Responses and Messages APIs, and our openrouter:bash tool does the same on the Messages API only. Both tools are in beta.
Our sandbox is an isolated container scoped to your account and workspace, with outbound network access off by default and per-command limits on runtime and output size. Sandbox time is billed at $0.0001 per second with a 30-second minimum for a new or sleeping container.
A sandbox platform you operate yourself is still the right choice for a custom base image, GPU work, or a session that runs for hours.
What server-side code execution means
By subscribing you agree to receive the OpenRouter newsletter: model usage data, product updates, and research reports, about one email a week. Unsubscribe anytime via the link in every email. See our Privacy Policy .
A model never runs anything itself. When it calls a tool, it emits a request naming the tool and the arguments, and something has to carry that out. With a client-side tool, that something is your application code or the agent framework you build on. Your application receives the call, runs it, and sends the result back in a follow-up request. With a server-side tool, the provider runs the call on its own infrastructure and returns the result to the model in the same request, so your application has no handler for it. Server-side code execution is the second kind.
You may already use tools that work this way. Web search lets a model look something up on the live web, and web fetch lets it read the contents of a URL. In both cases you add one entry to the request and the provider does the rest. Code execution applies the same pattern to running commands.
These steps apply to any server-side code execution tool. Where a field name appears, it’s the one our shell tool uses.
You include the tool in the request’s tools array.
The model decides it needs to run something and emits a call carrying one or more shell commands.
The provider runs those commands in order inside a sandboxed container.
Each command’s standard output, standard error, and outcome go back to the model. The outcome is either an exit code or a timeout.
The model reads the results and either answers you or runs more commands in the same request.
Steps two through five repeat until the model answers. The model runs something, reads the output, decides whether it needs another command, and goes again. That loop is where a code execution tool earns its place, because the model can check its work against real output instead of guessing.
We cap that loop. The max_tool_calls field sets how many server-tool steps one request may take. Our server tools reference puts both the default and the maximum at 30.
How a hosted sandbox differs from one you run yourself
Running your own sandbox means owning the parts the provider would otherwise own. You pick a base image, provision the compute, wire in an SDK to start runs and read output, and manage each run’s lifecycle. You also own the security boundary.
A hosted tool trades that control for one entry in a JSON array. You don’t size the container, patch it, or operate it. We built openrouter:shell for the case where the work is a handful of short commands per request.
Who offers hosted code execution today
This article covers OpenAI, Anthropic, Google, and OpenRouter. Agent SDKs and dedicated sandbox platforms are separate categories, and both come later in the article. What separates the four providers is which models each one runs code for.
OpenAI runs a hosted shell for OpenAI models
OpenAI’s shell tool runs commands in a container OpenAI manages, on the Responses API. OpenAI documents the hosted runtime as Debian 12 with a default working directory of /mnt/data . Commands run without sudo , and interactive TTY sessions aren’t supported. Preinstalled languages listed in the documentation include Python 3.11, Node.js 22.16, Java 17, PHP 8.2, Ruby 3.1, and Go 1.23.
Hosted containers have no outbound network access by default. To enable it, an organization admin configures an allowlist in the OpenAI dashboard and you set network_policy on the container environment in the request. A container can be reused across requests by passing its id in a container_reference environment, and its expiry is set when the container is created. OpenAI also has a separate code interpreter tool for Python.
Anthropic runs Python and Bash for Claude models
Anthropic’s code execution tool runs Python and Bash in a sandbox Anthropic manages, on the Messages API. The documented environment is a Linux x86_64 container with Python 3.11, 5 GiB of RAM, 5 GiB of workspace storage, and one CPU. Internet access is disabled and no outbound connections are permitted, so Claude works with the preinstalled libraries and can’t install a package during a run.
Three tool versions exist, and every supported model accepts all three. code_execution_20250825 supports Bash commands and file operations. code_execution_20260120 adds Python interpreter state that persists between requests, which depends on Anthropic’s programmatic tool calling and isn’t available on Claude Haiku 4.5. Containers expire 30 days after creation. After about 5 minutes of inactivity a container is checkpointed, and a request with its id inside the 30-day window restores it.
Google runs Python for Gemini models
Google’s code execution tool runs Python in a sandbox Google manages, enabled with a code_execution entry in the request’s tools. The documentation states that the model can only generate and execute Python, that the code environment has a maximum runtime of 30 seconds, and that you can’t install your own libraries. Google publishes the list of libraries the environment includes.
We run a hosted shell for any model
The three tools above each work with one company’s models. Ours works with any model on the Responses and Messages APIs, because we run the sandbox at the routing layer rather than inside one model provider.
We ship two code execution tools. openrouter:shell mirrors the shape of OpenAI’s hosted shell tool and works on both the Responses API and the Messages API. openrouter:bash mirrors the shape of Anthropic’s bash tool and works on the Messages API only.
Both tools are in beta, so the API may change. Sandboxed execution runs on the global openrouter.ai endpoint only. The in-region endpoints don’t offer the shell tool, and Chat Completions rejects both tools with a 400 that names the APIs that do support them.
Set engine to openrouter on either tool and the commands run in our sandbox. The default engine is auto . For openrouter:shell, auto keeps a provider’s native hosted shell where one exists and routes to our sandbox otherwise. For openrouter:bash, auto returns the tool call to your application to run client-side, and nothing executes on our servers.
Run a command in our sandbox
Here is a complete request that runs two commands and reads the results back.
import os
import requests
response = requests.post(
"https://openrouter.ai/api/v1/responses" ,
headers = { "Authorization" : f "Bearer { os.environ[ 'OPENROUTER_API_KEY' ] } " },
json = {
"model" : "anthropic/claude-sonnet-4.5" ,
"input" : "Run cat /etc/os-release and python3 --version, then tell me the OS and Python version in one sentence." ,
"tools" : [
{ "type" : "openrouter:shell" , "parameters" : { "engine" : "openrouter" }}
],
},
)
for item in response.json()[ "output" ]:
if item[ "type" ] == "openrouter:shell" :
print (item[ "container_id" ], item[ "action" ][ "commands" ])
for result in item[ "output" ]:
print (result[ "stdout" ], result[ "outcome" ])
We ran this request on September 22, 2026. The model sent both commands in one shell call, and each command came back with its own outcome. The full os-release output runs to several lines and is trimmed to its first two here.
{
"type" : "openrouter:shell" ,
"container_id" : "sess_art10-418b8597e044" ,
"action" : { "commands" : [ "cat /etc/os-release" , "python3 --version" ] },
"output" : [
{
"stdout" : "PRETTY_NAME= \" Ubuntu 22.04.5 LTS \"\n NAME= \" Ubuntu \"\n " ,
"stderr" : "" ,
"outcome" : { "type" : "exit" , "exit_code" : 0 }
},
{
"stdout" : "Python 3.11.14" ,
"stderr" : "" ,
"outcome" : { "type" : "exit" , "exit_code" : 0 }
}
]
}
The sandbox reported Ubuntu 22.04.5 LTS with Python 3.11.14 on that date. The runtime image can change, so read the version from the container rather than hard-coding it. The server tools reference covers the remaining parameters.
Agent SDKs that wrap a sandbox for you
If you build on an agent SDK rather than calling an API directly, some SDKs wrap one of these tools.
The OpenAI Agents SDK ships CodeInterpreterTool , which runs code in OpenAI’s sandbox, and ShellTool , which runs either in your local runtime or in an OpenAI-hosted container depending on how you configure its environment. Check which mode you configured before assuming a command ran remotely. On our side, openrouter:shell is an entry in the tools array like any other, so it goes into an OpenRouter Agent SDK loop the same way it goes into a raw request.
What still needs a sandbox of your own
A hosted tool fits short, bounded work such as running a script, transforming a file, or checking a result. Anything that needs a specific base image or a GPU falls outside all four hosted tools and needs a sandbox platform you operate.
Comparison
Every hosted-tool cell comes from the vendor’s own documentation linked above, except the OpenRouter runtime cell, which is what the sandbox reported when we ran the request above. The self-managed column describes a sandbox you run yourself rather than any one platform.
OpenRouter OpenAI Anthropic Google Self-managed
Who runs it We do OpenAI Anthropic Google You do
Models Any model on the Responses and Messages APIs OpenAI models Claude models Gemini models Any model
APIs Responses and Messages. openrouter:bash is Messages only Responses Messages Gemini API Any
Languages Any shell command. Ubuntu 22.04.5 with Python 3.11.14 reported on September 22, 2026 Shell commands on Debian 12. Python, Node.js, Java, PHP, Ruby, and Go preinstalled Python and Bash Python only Whatever you build
Filesystem Own container filesystem, scoped to your account and workspace. Files under the home directory are saved after every command Own container filesystem with a default working directory of /mnt/data . Data is deleted when the container expires Isolated container with 5 GiB of workspace storage. Containers expire 30 days after creation Not documented Whatever your image and mounts define
Outbound network Off by default. Allowlist of up to 50 hostnames on ports 80 and 443 Off by default. Organization allowlist plus a per-request network_policy Disabled Not documented Yours to configure
Install packages at runtime Yes, with the package hosts in the allowlist Yes, with the package hosts in the allowlist No No Yes
Session persistence Container keyed by container id. Sleeps after 5 minutes idle. Saved files kept for 30 days after last use Container reused by id through container_reference . Expiry set on the container Container restored by id within 30 days of creation. Interpreter state persists on code_execution_20260120 and later with programmatic tool calling 30-second maximum runtime per execution. State persistence between requests not documented Up to each platform’s cap
Cost model Inference tokens plus sandbox time at $0.0001 per second, with a 30-second minimum for a new or sleeping container Not stated in the shell tool documentation 1,550 free hours per organization per month, then $0.05 per hour per container, with a 5-minute minimum per execution No added charge. Generated code and output billed as tokens Compute time while the sandbox runs
What our sandbox enforces
The point of a sandbox is that you don’t have to trust the model. A command you never intended can’t reach the network or anyone else’s container, and it stops at a hard limit on how long it runs and how much it prints. Everything in this section describes our sandbox. The table above shows where the other three differ.
The limits that apply to every command
We run each command in an isolated container, separate from the infrastructure serving your request and from your machine, and scoped to your account and workspace. You set your own ceilings with timeout_ms for how long a command may run and max_output_length for how much it may print. timeout_ms defaults to 120,000 ms and can’t exceed 300,000 ms. max_output_length defaults to 16,384 characters per stream and can’t exceed 65,536. A shell call with more than 100 commands is rejected.
Outbound network access is off unless you turn it on. We checked this on September 22, 2026 by sending a request with no network_policy and asking the model to fetch https://example.com with curl , printing only the HTTP status code and giving up after 5 seconds. The command printed 000 , which is what curl prints when no response arrives, and exited with code 28, a curl timeout.
{ "stdout" : "000" , "stderr" : "curl: (28) Failed to connect to example.com port 443 after 5206 ms: Connection timed out" , "outcome" : { "type" : "exit" , "exit_code" : 28 } }
To open the network, set a network_policy allowlist of up to 50 hostnames or glob patterns. Only ports 80 and 443 are reachable, and the policy is fixed when the container starts. pip install needs both pypi.org and files.pythonhosted.org in the allowlist.
Prompt injection and what the sandbox limits
Giving a model a shell exposes you to prompt injection . If your agent reads a web page, a support ticket, or a file someone uploaded, an attacker can hide instructions in that text telling the model to ignore your prompt and run something else.
The limits above apply whether the model is following your prompt or an attacker’s. A command run under an injected instruction can’t reach any host outside the network_policy you configured, and has no network access at all when you leave the policy off. It can’t reach another tenant’s container, and it stops at the same timeout. An allowlist widens what an injected command can reach, and allowed_domains: ["*"] permits unrestricted egress, so keep the allowlist to the hosts the job needs.
You can also detect an attempt that arrives in the request itself. Prompt-injection detection in a workspace guardrail checks the user-supplied message content of each incoming request against regex patterns for common injection techniques, before we forward the request to the model. It doesn’t inspect what a server tool fetches after that point, so a page, file, or command output the model reads through a tool needs a control of your own, su
| 刊期 | 得分 | 排名 | 结果 |
|---|---|---|---|
| 2026-10-26 | 8.4 | 13 | 入选 |
| 2026-10-25 | 8.4 | 21 | 未入选 |
| 2026-10-24 | 8.4 | 40 | 未入选 |
| 2026-10-23 | 8.4 | 56 | 未入选 |
| 2026-10-22 | 8.4 | 51 | 未入选 |
| 2026-10-21 | 8.4 | 49 | 未入选 |
| 2026-10-20 | 8.4 | 34 | 未入选 |
| 2026-10-19 | 8.4 | 25 | 未入选 |
| 2026-10-18 | 8.4 | 33 | 未入选 |
| 2026-10-17 | 8.4 | 45 | 未入选 |
| 2026-10-16 | 8.4 | 47 | 未入选 |
| 2026-10-15 | 8.4 | 41 | 未入选 |
| 2026-10-14 | 8.4 | 36 | 未入选 |
| 2026-10-06 | 9.94 | 22 | 入选 |