﻿---
title: "tools.web_search 对象管域名和上下文，不是搜索模式"
summary: "顶层 web_search 选 cached / live / disabled。要限制可搜域名或 context_size，用 [tools.web_search] 对象。这不管沙箱出站，也不拦 MCP。"
category: config
level: intermediate
surfaces: [cli, app]
tags: ["tools.web_search", "allowed_domains", "web_search"]
canonical: /tips/tools-web-search-object/
---

# tools.web_search 对象管域名和上下文，不是搜索模式

顶层 web_search 选 cached / live / disabled。要限制可搜域名或 context_size，用 [tools.web_search] 对象。这不管沙箱出站，也不拦 MCP。

顶层 `web_search = "cached"` 只决定走缓存还是现场抓取。要收紧「搜哪些站、搜索上下文多大」，用工具表里的对象，不要再写 `[features] web_search_request`：

```toml
web_search = "cached"

[tools.web_search]
context_size = "medium"
allowed_domains = ["developers.openai.com", "learn.chatgpt.com"]
```

官方参考：布尔形式的 `[tools] web_search = true` 仍能解析，但对象才能设 `context_size`（`low` / `medium` / `high`）、`allowed_domains`，以及可选的大概地理位置。搜索域名过滤**不是**沙箱命令的网络域名规则，也不限制连接器或 MCP。

`--yolo` 或满权限沙箱仍会把**模式**默认改成 live；域名白名单挡不住模式被抬成 live。不要靠这个对象给模型「断网」。改完新开会话。

## 来源

- [OpenAI · Configuration reference](https://developers.openai.com/codex/config-reference)
