OpenAI 创建智能体环境模板

2026-11-18 17:53 更新

post /agents/environments/templates

创建可复用的环境配置。响应省略机密的初始化命令和环境变量值。参见复用托管配置。

请求体参数

内容类型为 application/json。

  • capability_directories: optional array of string or null

包含可向智能体提供的能力的目录。默认为空列表。

minItems: 0, maxItems: 16384

  • desktop: optional object { enabled } or null

桌面配置。省略或传入 null 时继承模板设置,无模板设置时默认禁用。

  • enabled: boolean

是否配置桌面及其浏览器代理。

  • env: optional map[string] or null

向智能体提供的环境变量。

  • files: optional array of HostedEnvironmentFileParam or null

智能体启动前可用的文件。默认为空列表。

minItems: 0, maxItems: 50

  • FileID object { file_id, path, type }

此前通过 OpenAI Files API 上传的文件。

  • file_id: string

已上传文件的 ID。

minLength: 1, maxLength: 256

  • path: string

/workspace 内的目标绝对路径。

minLength: 1, maxLength: 4096

  • type: "file_id" (default: "file_id")

对象类型,固定为 file_id。

  • "file_id"

  • Inline object { data, path, type }

直接以标准 Base64 数据提供的文件。

  • data: string

采用标准 Base64 编码的文件内容。

minLength: 0, maxLength: 6990508

  • path: string

/workspace 内的目标绝对路径。

minLength: 1, maxLength: 4096

  • type: "inline" (default: "inline")

对象类型,固定为 inline。

  • "inline"

  • name: optional string or null

模板的可选显示名称。

minLength: 1, maxLength: 256

  • network: optional object { access, allowed_domains, blocked_domains } or null

环境的网络访问策略。省略时,由 API 版本决定是否启用网络访问。

  • access: "enabled" or "disabled" or "restricted"

环境的网络访问模式。

  • "enabled"

允许不受限制的网络访问。

  • "disabled"

关闭网络访问。

  • "restricted"

应用配置的域名访问限制。

  • allowed_domains: optional array of string or null

网络访问受限时,环境可以访问的域名。

minItems: 0, maxItems: 16384

  • blocked_domains: optional array of string or null

网络访问受限时,执行器和浏览器均禁止访问的域名。列表非空时须设置 access: restricted,且 allowed_domains 必须为空。不支持通配符域名。

minItems: 0, maxItems: 100

  • packages: optional object { npm, python, system } or null

要安装到环境中的软件包。软件包列表默认为空。

  • npm: optional array of string or null

要全局安装的 npm 软件包。默认为空列表。

minItems: 0, maxItems: 16384

  • python: optional array of string or null

要安装的 Python 软件包。默认为空列表。

minItems: 0, maxItems: 16384

  • system: optional array of string or null

要安装的系统软件包。默认为空列表。

minItems: 0, maxItems: 16384

  • plugins: optional array of HostedPluginParam or null

以内联 ZIP 归档提供的插件。默认为空列表。

minItems: 0, maxItems: 32

  • description: string

.codex-plugin/plugin.json 中声明的插件描述。

minLength: 0, maxLength: 1048576

  • name: string

.codex-plugin/plugin.json 中声明的插件名称。

minLength: 1, maxLength: 64

  • source: InlineCapabilitySourceParam

提供以标准 Base64 编码的 ZIP 数据。

  • data: string

采用标准 Base64 编码的 ZIP 归档数据。

minLength: 1, maxLength: 70254592

  • media_type: "application/zip" (default: "application/zip")

归档文件的媒体类型,固定为 application/zip。

  • "application/zip"

  • type: "base64" (default: "base64")

对象类型,固定为 base64。

  • "base64"

  • type: "inline" (default: "inline")

对象类型,固定为 inline。

  • "inline"

  • setup_commands: optional array of SetupCommandParam or null

按顺序执行的机密初始化命令。响应始终省略命令正文。

minItems: 0, maxItems: 16

  • command: string

要执行的 Shell 命令。

minLength: 0, maxLength: 65536

  • cwd: optional string or null

工作目录的绝对路径,默认为 /workspace。

minLength: 0, maxLength: 4096

  • skills: optional array of HostedSkillParam or null

通过 ID 引用或以内联 ZIP 归档提供的技能。默认为空列表。

minItems: 0, maxItems: 200

  • SkillReference object { skill_id, type, version }

引用通过 Skills API 上传的技能。

  • skill_id: string

通过 /v1/skills 创建的技能 ID。

minLength: 1, maxLength: 64

  • type: "skill_reference" (default: "skill_reference")

对象类型,固定为 skill_reference。

  • "skill_reference"

  • version: optional string or null

技能版本,可以是正整数或 latest。省略时选择默认版本。

minLength: 0, maxLength: 1048576

  • Inline object { description, name, source, type }

直接在会话请求中提供技能 ZIP。

  • description: string

SKILL.md 中声明的技能描述。

minLength: 0, maxLength: 1048576

  • name: string

SKILL.md 中声明的技能名称。

minLength: 1, maxLength: 64

  • source: InlineCapabilitySourceParam

提供以标准 Base64 编码的 ZIP 数据。

  • type: "inline" (default: "inline")

对象类型,固定为 inline。

  • "inline"

返回值

  • EnvironmentTemplate object { id, capability_directories, created_at, 9 more }

可复用的配置,用于为每个会话创建新的 OpenAI 托管环境。

  • id: string

可复用的环境模板 ID。

minLength: 0

  • capability_directories: array of string

用于向智能体提供能力的目录。

minItems: 0, maxItems: 2000

  • created_at: integer

模板创建时的 Unix 时间戳,单位为秒。

format: int64

  • desktop: object { enabled }

每个 OpenAI 托管环境的桌面配置。

  • enabled: boolean

环境是否配置桌面及浏览器代理。

  • files: array of FileID { file_id, path, type } or Inline { path, size_bytes, type }

可返回的文件元数据,省略文件内容和会话范围的文件 ID。

minItems: 0, maxItems: 50

  • FileID object { file_id, path, type }

项目范围内的 Files API 引用,每个会话独立解析。

  • file_id: string

已上传文件的 ID。

minLength: 0

  • path: string

文件在环境内的绝对路径。

minLength: 0

  • type: "file_id" (default: "file_id")

对象类型,固定为 file_id。

  • "file_id"

  • Inline object { path, size_bytes, type }

机密内联文件内容的元数据。

  • path: string

文件在环境内的绝对路径。

minLength: 0

  • size_bytes: integer

内联文件解码后的大小,单位为字节。

format: int64, minimum: 0

  • type: "inline" (default: "inline")

对象类型,固定为 inline。

  • "inline"

  • name: string or null

模板的可选显示名称。

minLength: 0

  • network: object { access, allowed_domains }

每个 OpenAI 托管环境的运行时网络访问配置。

  • access: "enabled" or "disabled" or "restricted"

环境的网络访问模式。

  • "enabled"

允许不受限制的网络访问。

  • "disabled"

关闭网络访问。

  • "restricted"

应用配置的域名访问限制。

  • allowed_domains: array of string

网络访问受限时,环境可以访问的域名。

minItems: 0, maxItems: 2000

  • object: "agent.environment.template" (default: "agent.environment.template")

对象类型,固定为 agent.environment.template。

  • "agent.environment.template"

  • packages: object { npm, python, system }

每次新建 OpenAI 托管环境时安装的软件包。

  • npm: array of string

在环境中全局安装的 npm 软件包。

minItems: 0, maxItems: 16384

  • python: array of string

已安装到环境中的 Python 软件包。

minItems: 0, maxItems: 16384

  • system: array of string

已安装到环境中的系统软件包。

minItems: 0, maxItems: 16384

  • plugins: array of HostedPlugin

可返回的插件元数据,省略内联归档内容。

minItems: 0, maxItems: 32

  • description: string

已安装插件的描述。

minLength: 0

  • name: string

已安装插件的名称。

minLength: 0

  • type: "inline" (default: "inline")

对象类型,固定为 inline。

  • "inline"

  • skills: array of SkillReference { skill_id, type, version } or Inline { description, name, type }

可返回的技能元数据,保留尚未解析的版本选择值。

minItems: 0, maxItems: 200

  • SkillReference object { skill_id, type, version }

每次启动会话时都通过 Skills API 重新解析的技能。

  • skill_id: string

引用的技能 ID。

minLength: 0

  • type: "skill_reference" (default: "skill_reference")

对象类型,固定为 skill_reference。

  • "skill_reference"

  • version: string or null

请求的版本选择值,包含 latest 选项。

minLength: 0

  • Inline object { description, name, type }

可以安全返回的内联技能归档元数据。

  • description: string

SKILL.md 中声明的技能描述。

minLength: 0

  • name: string

SKILL.md 中声明的技能名称。

minLength: 0

  • type: "inline" (default: "inline")

对象类型,固定为 inline。

  • "inline"

  • updated_at: integer

模板上次更新时的 Unix 时间戳,单位为秒。

format: int64

示例

## 从环境变量读取 API 密钥。
## 此官方示例仅展示请求地址和请求头。发送前请按上方参数补充 JSON 请求体及 Content-Type 请求头。
curl https://api.openai.com/v1/agents/environments/templates \
    -X POST \
    -H 'OpenAI-Beta: agents=v1' \
    -H "Authorization: Bearer $OPENAI_API_KEY"

201 响应示例

字段名、类型值和示例标识均按接口定义保留。

{
  "id": "id",
  "capability_directories": [
    "string"
  ],
  "created_at": 0,
  "desktop": {
    "enabled": true
  },
  "files": [
    {
      "file_id": "file_id",
      "path": "path",
      "type": "file_id"
    }
  ],
  "name": "name",
  "network": {
    "access": "enabled",
    "allowed_domains": [
      "string"
    ]
  },
  "object": "agent.environment.template",
  "packages": {
    "npm": [
      "string"
    ],
    "python": [
      "string"
    ],
    "system": [
      "string"
    ]
  },
  "plugins": [
    {
      "description": "description",
      "name": "name",
      "type": "inline"
    }
  ],
  "skills": [
    {
      "skill_id": "skill_id",
      "type": "skill_reference",
      "version": "version"
    }
  ],
  "updated_at": 0
}
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号