终端沙箱将 Agent shell 命令隔离在操作系统级容器边界内,以保护您的工作站和敏感文件。
Antigravity App
更新后的权限设置
概览
Antigravity includes a terminal sandbox, enabled by default, that isolates shell commands executed by agents. Sandboxed commands can write to your project folders, temporary directories, and common build caches, and read system directories such as /usr and /etc so your tools keep working. Sensitive files such as ~/.ssh and .env are blocked, anything not explicitly mounted is invisible inside the sandbox, and network access is limited to domains you’ve approved.
沙箱是基于本机操作系统原语构建的,因此无需管理虚拟机或 Docker 映像,也没有启动延迟:
| 操作系统 | 技术 | 详情 |
|---|---|---|
| Linux | 命名空间 | 内核命名空间隔离文件系统、隐藏主机进程并切断网络。 |
| macOS | sandbox-exec | macOS Seatbelt 配置文件 (SBPL) 会限制文件系统访问与套接字连接。 |
配置
Your permission preset controls whether the sandbox is used:
| 预设 | 沙箱 (Sandbox) | 命令 |
|---|---|---|
| 请求审查 | 关闭 | 总是问 |
| Default (default) | 开启 | 允许在沙箱中使用;到外面去问 |
| 自动 | 开启 | Allowed in sandbox; safe, reversible commands allowed outside |
| Turbo | 关闭 | 无需提示即可允许,不受限制 |
You can change your preset in three places:
- 所有项目:打开 Settings > General > Global Permissions > Permission Preset(如果您可以使用远程 Agent,则为 Permissions > This Computer)。
- For a single project: Override the global preset under Settings > Projects. Projects default to Inherit Global upon creation, which follows your global preset.
- From the message box (
v2.23.0+): Choose a preset from the permissions picker. The picker changes your global preset, or the project’s preset if the project overrides it. To remove a project override, choose Use Global Settings.
请参阅 Agent 权限 了解完整的预设行为,包括文件访问、MCP 工具和网页读取。
非沙箱命令
Some commands cannot work inside the sandbox—for example, those needing network access or talking to system services. The agent can request to run such commands outside the sandbox, where they run on your host with full privileges:
- Default: Requests to run outside the sandbox always pause for your approval, unless the command is already covered by a
commandallow or deny rule. - Auto(macOS 和 Linux 需
v2.23.0+,Windows 需v2.26.0+):Antigravity 会自动检查需要在沙箱外运行的命令,使安全、可逆的命令无需提示即可运行,而存在风险或不可逆的命令仍会暂停并等待您的批准(除非已匹配command允许或拒绝规则)。
要让特定命令在没有提示的情况下运行(在沙箱内部或外部),请添加 command 允许规则:
command(git push)
command(regex:docker compose .*)权限集成
沙箱从您的 权限 配置中获取其访问边界:
- 文件系统:您的项目文件夹以读写方式安装。在默认系统安装之上,
read_file下允许的路径以只读方式安装,write_file下允许的路径以读写方式安装。其他一切都无法访问。 - 网络:默认情况下,沙箱命令无需网络访问即可运行。
read_url下允许的域将添加到沙箱的出站白名单中。
旧版权限设置
概览
Antigravity includes a terminal sandbox that isolates shell commands executed by agents. Sandboxed commands can write to your project folders, temporary directories, and common build caches, and read system directories so your tools keep working. Sensitive files such as .env are blocked, and network access is limited to domains you’ve approved. On macOS and Linux, anything not explicitly mounted is invisible inside the sandbox. On Windows, the sandbox requires Windows 11 24H2 or later with the August 2026 update or later, and folders outside your user profile are readable but not writable inside it.
配置
您可以全局或每个项目配置沙箱。
全局设置
在 设置 > 一般的 中的 Agent 设置 下,配置以下选项:
- 启用沙箱模式(预览):在沙箱内运行 Agent 终端命令。
- 终端命令自动执行:设置为在沙箱中继续,让沙箱命令无需批准即可运行;需要在沙箱外运行的命令仍然首先询问。其他选项是 需要审核 和 始终继续。
项目设置
Select a project under Settings > Projects to override these settings for that project. Each setting gains an Inherit Global option, and Enable Sandbox Mode becomes a dropdown: Inherit Global, Enabled, or Disabled.
安全预设方案
同一设置部分中的 安全预设 下拉列表捆绑了终端和文件访问策略:
| 预设 | 终端命令自动执行 | 文件夹外文件访问 |
|---|---|---|
| 默认值 | 需要审核 | 总是问 |
| 整机 | 需要审核 | 允许 |
| 涡轮增压模式 | 始终继续 | 允许 |
所有预设均不会打开沙箱。启用 启用沙箱模式 会将预设切换为 风俗,您可以自己设置每个选项 - 常见的组合是沙箱与 在沙箱中继续。
非沙箱命令
当命令需要在沙箱外部运行时(因为它与 unsandboxed(...) 规则匹配、Agent 请求它或沙箱被禁用),该命令会在您的主机上以完全权限运行。根据您的执行策略,Agent 会首先暂停以等待您的批准。
权限集成
沙箱从您的 权限 配置中获取其访问边界:
- Filesystem: Your project folders are mounted read-write. Paths allowed under
read_fileare mounted read-only, and paths allowed underwrite_fileare mounted read-write, on top of the default system mounts. Everything else is inaccessible, except that on Windows, folders outside your user profile stay readable. - 网络:启用网络访问时,
read_url下允许的域将添加到沙箱的出站白名单中。 - Escape hatches (
unsandboxed): To let specific commands run outside the sandbox without disabling it entirely, add anunsandboxedallow rule:unsandboxed(git push) unsandboxed(docker compose .*)
Antigravity CLI
工作原理
With the terminal sandbox enabled, Antigravity CLI executes commands inside an OS-level isolation boundary. Commands can write to your workspace, temporary directories, and common build caches, and read system directories (such as /usr and /etc on macOS and Linux) so your tools keep working. Sensitive files such as ~/.ssh and .env are blocked, and network access is limited to domains you’ve approved. On macOS and Linux, anything not explicitly mounted is invisible inside the sandbox. On Windows, folders outside your user profile are readable but not writable inside the sandbox, and other files in your user profile and other users’ profiles stay hidden.
沙箱是基于本机操作系统原语构建的,因此无需管理虚拟机或 Docker 映像,也没有启动延迟:
| 操作系统 | 技术 | 详情 |
|---|---|---|
| Linux | 命名空间 | 内核命名空间隔离文件系统、隐藏主机进程并切断网络。 |
| macOS | sandbox-exec | macOS Seatbelt 配置文件 (SBPL) 会限制文件系统访问与套接字连接。 |
| Windows | Process security environments | Commands run in an AppContainer inside a process security environment, which restricts filesystem and network access. Requires Windows 11 24H2 or later with the August 2026 update or later. |
CLI 配置
auto 模式会自动启用终端沙箱。在包括 default 模式在内的其他模式下,您可以在 ~/.gemini/antigravity-cli/settings.json 中启用沙箱,或使用 /config 交互式启用:
{
"enableTerminalSandbox": true,
"toolPermission": "proceed-in-sandbox"
}该配置支持以下设置:
agentMode(字符串,默认值:在"auto"支持该模式的环境中为v1.5.7+,否则为表示""模式的default):设置"agentMode": "auto"会自动启用终端沙箱,使命令默认在沙箱内运行,并自动评估需要在沙箱外运行的命令,从而使安全、可逆的命令无需提示即可直接运行,而存在风险或不可逆的命令则会暂停并等待批准。请参阅选择执行模式。enableTerminalSandbox(布尔值,默认值:false):在沙箱内运行 Agent 命令。auto模式会自动开启此项。toolPermission(字符串,默认值:"request-review"):在auto模式之外,将其设置为"proceed-in-sandbox"可让沙箱内的命令自动运行,而需要在沙箱外运行的命令仍会提示审阅。有关其他模式,请参阅设置。
CLI 命令行参数
您还可以在启动 CLI 时控制沙箱:
# Force the sandbox on for this session
agy --sandbox
# Launch in auto mode (enables the sandbox and automatically evaluates commands that need to run outside it)
agy --mode=autoThe CLI supports the following sandbox and execution flags:
--sandbox:为会话打开沙箱,覆盖settings.json。--mode=auto: Runs commands inside the sandbox by default and automatically checks commands that need to run outside the sandbox so safe, reversible commands proceed without prompting.
如果沙箱不可用
Starting in v1.4.4, the following applies if the sandbox isn’t available on your machine (for example, on Windows 10, earlier Windows 11 builds, or Linux hosts and some containers that block unprivileged user namespaces):
enableTerminalSandboxand--sandboxhave no effect.proceed-in-sandboxbehaves likerequest-review.automode isn’t offered./confighides Sandbox Mode,proceed-in-sandbox, andauto.
Your saved settings aren’t changed, so they take effect once the sandbox is available.
CLI 权限集成
沙箱从您的 权限 配置中获取其访问边界:
- Filesystem: Workspace folders and paths allowed under
write_fileare mounted read-write. Paths allowed underread_fileare mounted read-only, on top of the default system mounts. Denied paths are blocked, and everything else is inaccessible, except that on Windows, folders outside your user profile stay readable. - 网络:默认情况下,沙箱命令无需网络访问即可运行。
read_url下允许的域将添加到沙箱的出站白名单中。 - Commands outside the sandbox: A
commandallow rule lets a matching command run without prompting, inside or outside the sandbox. This is useful for tools that can’t work inside the isolation boundary, such as Docker or commands that talk to system services. Business and enterprise accounts use anunsandboxedallow rule for this instead.
The agent can also request to run a command outside the sandbox on its own—for example, to retry a command that failed due to sandbox restrictions. On Windows, this includes some package installs and commands that connect to servers running outside the sandbox. How Antigravity CLI handles these requests depends on your mode:
auto模式(macOS 和 Linux 需v1.3.5+,Windows 需v1.4.4+):Antigravity CLI 会自动评估需要在沙箱外运行的命令,使安全、可逆的命令无需提示即可运行,而不可逆的命令仍会提示确认。- Modes other than
auto: These requests always require your approval unless the command matches acommandallow rule (anunsandboxedallow rule for business and enterprise accounts).
示例
以下示例在 settings.json 中配置沙箱允许和拒绝规则:
{
"permissions": {
"allow": [
"command(npm test)",
"command(git diff)",
"command(git push)",
"read_file(/var/log/app)",
"write_file(src/)"
],
"deny": [
"command(rm -rf /)",
"command(sudo *)",
"write_file(/home/user/.ssh)"
]
}
}使用此配置:
npm test和git diff在沙箱内运行。git pushruns without prompting, even when it needs to run outside the sandbox, throughcommand(git push).rm -rf /和sudo始终被阻止。
交互式提示
当命令需要审核时,您可以批准一次或将批准变成长期规则:
Do you want to proceed?
1. Yes
2. Yes, and always allow in this conversation for commands that start with 'npm test'
3. Yes, and always allow for commands that start with 'npm test' (Persist to settings.json)
4. NoFor business and enterprise accounts, when the agent asks to bypass the sandbox, the prompt calls it out explicitly so you can judge the risk:
🔓 Allow sandbox bypass for command execution?
⚠️ Confirm the command is safe to run outside of the sandbox with full network and disk access.此处批准“始终允许”会记录 unsandboxed(...) 规则,而不是普通的 command(...) 规则。
For other accounts, these requests use the standard command prompt, and “always allow” records a command(...) rule.
相关资源
探索相关文档和指南:
- Verification and guardrails: Pair OS-level sandboxing with permissions, tests, and diff review.
- Agent 权限:配置允许、拒绝和询问规则。
- Agent 设置:命令执行策略和文件访问控制。
- 设置:全局应用程序和 CLI 首选项。
- 项目:多文件夹配置和每个项目设置。