https://t.co/IFXwxW8Oac
TL;DR · AI 摘要
本文介绍了如何通过Auth Proxy来保护LangSmith代理沙箱的网络访问,确保在大规模部署代理时的安全性。Auth Proxy通过在网络层控制和管理代理与外部服务的交互,实现了凭据的安全管理、网络访问的显式控制以及团队职责的清晰分离。
核心要点
- Auth Proxy使API密钥不进入运行时,从而减少因提示注入、恶意依赖、意外日志记录和模型错误导致的损害。
- 通过将网络访问编码为基础设施策略,可以明确限制代理只能与特定服务通信,如OpenAI、Anthropic、GitHub或内部API。
- 团队可以获得更清晰的职责分离:代理专注于任务,沙箱提供隔离,Auth Proxy处理网络授权和凭据注入,应用程序或认证服务处理用户范围的访问和令牌刷新。
结构提纲
按章节快速跳转。
- §引言
在大型企业中,标准的公司笔记本电脑设置包含多种安全工具,以防止受信任的员工意外泄露凭据、安装恶意软件或访问不当页面。这些工具的存在是因为开发者拥有广泛的访问权限,他们运行代码、安装依赖项并跨系统复制数据。随着代理技术的发展,安全问题的规模和性质发生了变化,需要新的安全措施来保护大规模部署的代理。
代理改变了安全问题的规模和性质,因为它们可能生成数千甚至数百万个“不受信任的开发者”,这些代理可以代表用户运行代码、执行命令、安装包和发出网络请求。与人类开发者不同,代理的环境可以默认为更受限的,仅允许必要的网络访问和凭据使用,以减少潜在的安全风险。
沙箱网络成为代理框架的重要组成部分,它为代理提供了隔离的环境,以运行代码和与文件系统交互,而不会影响主基础设施。然而,隔离只是故事的一部分,代理仍然需要与外部API交互,如模型提供商、GitHub、包注册表、内部服务和数据API等。
Auth Proxy是一种控制代理生成行为与外部世界之间边界的机制。它位于沙箱的出站网络路径上,控制沙箱代码如何与外部服务交互。通过Auth Proxy,可以管理哪些目的地是允许的,应用什么身份验证,以及如何塑造请求在离开沙箱之前。这样,沙箱代码可以像往常一样向外部API发出请求,而凭据和访问规则则在网络层由Auth Proxy处理,无需在运行时暴露凭据。
使用Auth Proxy有三个主要好处:首先,凭据不会进入运行时,减少了因提示注入、恶意依赖、意外日志记录和模型错误导致的损害;其次,网络访问变得显式,可以明确限制代理只能与特定服务通信;最后,团队可以获得更清晰的职责分离,即代理专注于任务,沙箱提供隔离,Auth Proxy处理网络授权和凭据注入,应用程序或认证服务处理用户范围的访问和令牌刷新。
Auth Proxy是一个受控的中介,管理沙箱的出站网络请求。当沙箱发出出站请求时,请求会通过Auth Proxy,后者检查配置的策略以确定如何处理该请求,包括允许、阻止或附加头信息。这样,凭据不会暴露给运行时,而是由Auth Proxy在需要时注入。
- §策略配置
Auth Proxy支持多种策略配置,可以针对不同的目的地定义不同的行为,例如注入特定的Authorization头或GitHub令牌。由于控制了沙箱的网络,这种机制是透明的,不需要依赖于各种运行时和包管理器对HTTP代理的遵守。
思维导图
用一张图看清主题之间的关系。
查看大纲文本(无障碍 / 无 JS 友好)
- Auth Proxy保护LangSmith代理沙箱网络访问
金句 / Highlights
值得收藏与分享的关键句。
Auth Proxy通过在网络层控制和管理代理与外部服务的交互,实现了凭据的安全管理、网络访问的显式控制以及团队职责的清晰分离。
通过将网络访问编码为基础设施策略,可以明确限制代理只能与特定服务通信,如OpenAI、Anthropic、GitHub或内部API。
团队可以获得更清晰的职责分离:代理专注于任务,沙箱提供隔离,Auth Proxy处理网络授权和凭据注入,应用程序或认证服务处理用户范围的访问和令牌刷新。
If you’ve ever worked at a large enterprise, you have probably seen the standard corporate laptop setup.
There’s endpoint protection, browser filtering, device management, network controls, certificate stores, secret scanners… a long list of tools whose job is to stop an otherwise trusted employee from accidentally leaking credentials, installing a malicious package, or visiting the wrong page.
That tooling exists because developers have broad access. They run code, install dependencies, and copy data between systems. They authenticate to internal and external services. A lot of enterprise security is built around making that powerful, open-ended environment safer.
Agents change the scale and shape of this problem. You’re not just giving one developer a laptop. You may be spawning thousands, or eventually millions, of “untrusted developers” that can write code, run commands, install packages, and make network requests on your behalf.
For human developers, the environment often needs to stay open by default. Developers need to explore, debug, install tools, and reach new services as their work changes. For agents, the default can be different. If the task is known, the network can be narrower. If the agent only needs GitHub and an LLM provider, it should not be able to talk to every random host on the internet. If it needs a credential, that credential should not have to exist inside the runtime at all.
This is where sandbox networking becomes a first-class part of the agent harness.
give agents isolated environments for running code and interacting with filesystems without affecting your main infrastructure. But isolation is only one part of the story. Agents still need to call external APIs like model providers, GitHub, package registries, internal services, data APIs, and more.
The
is a way to control the boundary between agent-generated behavior and the rest of the world.
Instead of putting API keys into the sandbox as environment variables or files, the proxy sits on the outbound network path and controls how sandboxed code interacts with external services. It can enforce policy for which destinations are allowed, what authentication is applied, and how requests are shaped before they leave the sandbox. Sandbox code makes a normal request to an external API, while credentials and access rules are handled outside the sandbox at the network layer.
Three things become much easier with this model:
- Credentials stay out of the runtime. The agent can use an API without being able to read the API key, which reduces the damage from prompt injection, malicious dependencies, accidental logging, and model mistakes.
- Network access becomes explicit. If an agent should only talk to OpenAI, Anthropic, GitHub, or an internal API, that should be encoded as infrastructure policy rather than left to the agent’s judgment.
- Teams get a cleaner separation of concerns: the agent focuses on the task, the sandbox provides isolation, the proxy handles network authorization and credential injection, and the application or auth service handles user-scoped access and token refresh.
This separation is important because agents are untrusted and you can’t review every branch they will take ahead of time. The safer pattern is to give them constrained environments where the possible actions are bounded by infrastructure, so the auth proxy keeps credentials out of the sandbox entirely.
At a high level, the auth proxy is a controlled intermediary for sandbox egress, which looks like this:
- The agent or sandboxed code makes an outbound request.
- The request passes through Auth Proxy.
- Auth Proxy checks the configured policy for that destination.
- The proxy can block the request, allow it, or attach headers.
- The request continues to the destination without exposing credentials to the runtime.
A simple rule might say: when the sandbox calls
, inject an Authorization header whose value comes from a LangSmith workspace secret. Another rule might say: when the sandbox calls
on /repos/* or /user, inject a GitHub token.
Because we control the network for the sandbox, this is completely transparent. This is not implemented by hoping every language, package manager, SDK, or subprocess respects HTTP_PROXY. Not all runtimes behave the same way, and agents often execute arbitrary code paths you didn’t write.
The proxy supports many different policy configurations. One powerful one is the ability to inject headers into requests that match certain characteristics.
Headers can be configured with different types:
workspace_secret: references a secret stored in LangSmith workspace settings
plaintext: stored and returned as-is, for non-sensitive headers
opaque: write-only, encrypted at rest, and never returned by the API
For example, in the example of the OpenAI rule, we can inject:
{
"name": "Authorization",
"type": "workspace_secret",
"value": "Bearer {OPENAI_API_KEY}"
}The sandbox code does not need to know the API key. It does not need an .env file. It does not need a secret mounted into its filesystem. It just calls the API, and the proxy adds the right header when the destination matches the configured rule.
This is a better default for agent systems. A human developer may need direct access to a credential to debug a new integration. An agent usually does not. The agent needs the effect of the credential — the ability to call a specific API — not possession of the credential itself.
That distinction becomes more important as the number of agent runs grows. With a single sandbox, a leaked key is bad, but for a fleet of sandboxes, putting credentials directly into runtimes is a significant risk. Every tool call, package install, log line, and file write is a possible credential exposure path. Header injection moves the credential out of that blast radius.
Credentials are only half the network problem; agents also need egress policy because they can install dependencies, fetch scripts, call APIs, and follow instructions from untrusted content. If every sandbox has open internet access, a compromised or confused agent can reach places it shouldn’t.
The same proxy boundary that injects headers can also become the place where teams define which destinations are expected, like:
- allowing the model provider API and blocking everything else
- allowing GitHub API paths the agent needs, but not arbitrary GitHub-adjacent domains
- allowing a package registry, but only the internal mirror
- blocking known malicious or untrusted package registries
- preventing accidental calls to unauthorized third-party services
This is especially important for package management. If a coding agent can runpip install,npm install, orcurl | bash, it can fetch and execute code. The security question is not just whether the sandbox can contain execution, but whether you can control where that code comes from and where it can send data.
While integrating sandboxes with LangSmith Fleet, we realized that for advanced use cases, static configuration may not be sufficient. Fleet agents may need delegated access and OAuth token refreshes while still keeping the actual credential handling outside the agent runtime.
Other examples of advanced use cases include:
- short-lived OAuth access tokens
- per-user-scoped tokens
- credentials minted by an internal auth service
- tokens that need to be refreshed based on the destination or current user context
For these cases, the auth proxy supports
.
Instead of putting all credential material into static rules, you configure a callback under proxy_config. When the sandbox makes a request to a matching host and the proxy does not have a cached credential, the proxy calls your callback endpoint with the target host and port. Your endpoint returns the headers to inject, and the proxy caches the result for a configured TTL.
The contract is simple: the callback returns a JSON object like:
{
"headers": {
"Authorization": "Bearer <token>",
"X-Org-Id": "..."
}
}The proxy injects those headers into the outbound request. If the callback fails, returns malformed JSON, or responds with a non-2xx status, the proxy fails closed and rejects the sandbox request rather than sending it without credentials. This is the pattern lets the sandbox network layer participate in auth flows without exposing refresh tokens or long-lived credentials to the sandbox.
Once you control the sandbox network path, the proxy can become more than a credential injector, and there are a few natural extensions.
- DNS remapping: a team may want requests to public package registries to resolve to an internal Artifactory or package mirror instead. You may want to point LLM API requests towards an internal gateway. The agent still runs normal install commands, but the network layer points those requests at approved infrastructure.
- Network logging: if agents are doing meaningful work over long horizons, teams will want to know which services they called, which packages they fetched, and which domains they attempted to reach. Network logs become part of the audit trail for agent behavior.
- Request transformation: since the proxy sees outbound requests, it can eventually become a place to apply deterministic transformations, such as redacting PII, adding organization metadata, enforcing request shape, or blocking payloads that violate policy.
The broader point is that agent infrastructure needs control planes that live outside the runtime and aren’t exposed to agent instructions and decisions.
Agents need credentials and network access to do useful work, but those capabilities should not require putting long-lived secrets or unrestricted internet access inside the runtime. Auth Proxy gives sandboxed agents a safer default by keeping credentials outside the environment, routing outbound traffic through a controlled layer, and applying policy consistently across languages, SDKs, package managers, and CLIs.
The result is a sandbox model that gives agents access to the systems they need, while keeping credentials and network policy under platform control.
Try LangSmith Sandboxes:
Read the docs: