﻿---
title: "Cloud 密钥只在 setup 阶段可见"
summary: "环境变量全程都在；Secrets 只给 setup 脚本，agent 阶段会被拿走。setup 里的 export 也不会带进 agent。"
category: cloud
level: intermediate
surfaces: [cloud]
tags: ["Cloud", "密钥", "setup"]
canonical: /tips/cloud-secrets-setup-only/
---

# Cloud 密钥只在 setup 阶段可见

环境变量全程都在；Secrets 只给 setup 脚本，agent 阶段会被拿走。setup 里的 export 也不会带进 agent。

Cloud 聊天分两段：先跑 setup（可上网装依赖），再进 agent 循环。默认 agent 阶段断网。

密钥和变量不要混用：

- 普通环境变量：setup 和 agent 都能看见
- Secrets：多一层加密，只在 setup 解密；agent 开始前删除
- setup 脚本是另一段 Bash，`export` 进不了 agent。要持久化就写进环境设置或 `~/.bashrc`

不要指望把生产密钥塞进 Secrets，再让 agent 用同样的值去调外部 API。需要 agent 访问时，用环境变量并收紧 internet allowlist，或把密钥只留给 setup 去写好本地工具链。

## 来源

- [OpenAI · Cloud environments](https://learn.chatgpt.com/docs/environments/cloud-environment)
- [OpenAI · Agent internet access](https://learn.chatgpt.com/docs/cloud/internet-access)
