ClaudeCloudflare Developer PlatformApr 13, 2026, 12:00 AM

Containers, Agents - Secure credential injection and dynamic egress policies for Sandboxes

A condensed section focused on the key takeaways first.

Original Post

Quick Digest

Summary

A condensed section focused on the key takeaways first.

claudeenmodel: claude-sonnet-4-20250514

Cloudflare Sandboxes: Secure Credential Injection and Dynamic Egress Policies

Key Points

  • Zero-trust credential injection without exposing secrets to sandboxed code
  • TLS interception with ephemeral per-instance certificate authorities
  • Dynamic runtime modification of egress policies without restart

Summary

Cloudflare has released new security features for Sandboxes and Containers, enabling zero-trust credential injection, TLS interception, and dynamic egress policies. These capabilities allow platforms to control outbound traffic from sandboxed workloads without exposing secrets to untrusted code.

Key Points

  • Secure Credential Injection: Credentials are managed in Workers runtime outside the sandbox, transparently attached to requests without exposing secrets to sandboxed workloads
  • TLS Interception: Ephemeral certificate authorities created per instance enable transparent proxying of HTTPS traffic
  • Dynamic Egress Control: Runtime modification of outbound policies using setOutboundHandler() and setOutboundByHost() without sandbox restart
  • Host Filtering: Support for allowedHosts and deniedHosts with glob pattern matching for traffic filtering
  • Per-Instance Policies: Unique credentials and policies per container using ctx.containerId for multi-tenant scenarios

Availability

Upgrade to @cloudflare/containers@0.3.0 or @cloudflare/sandbox@0.8.9 to access these features.

Full Translation

Translations

A translation section that keeps the flow of the original article.

claudejamodel: claude-sonnet-4-20250514

コンテナ、エージェント - Sandboxes向けのセキュアな認証情報インジェクションと動的エグレスポリシー

セキュアな認証情報インジェクションと動的エグレスポリシー for Sandboxes

2026年4月13日

SandboxesとContainers向けのOutbound Workersが、ゼロトラスト認証情報インジェクション、TLSインターセプション、許可/拒否リスト、および動的なインスタンス毎のエグレスポリシーをサポートするようになりました。これらの機能により、エージェント型ワークロードを実行するプラットフォームは、ユーザー生成コードやコーディングエージェントなどの信頼できないワークロードに秘密情報を公開することなく、サンドボックスから出るものを完全に制御できます。

認証情報インジェクション

アウトバウンドハンドラーはサンドボックスの外側のWorkers runtimeで実行されるため、サンドボックスが見ることのない秘密情報を保持できます。サンドボックス化されたワークロードは通常のリクエストを作成でき、リクエストが上流に転送される前に認証情報が透過的に付加されます。

例えば、サンドボックス内でエージェントを実行し、Githubへのリクエストが認証されることを保証できます。しかし、エージェントは認証情報にアクセスすることはできません:

export class MySandbox extends Sandbox {}

MySandbox.outboundByHost = {
  "github.com": (request: Request, env: Env, ctx: OutboundHandlerContext) => {
    const requestWithAuth = new Request(request);
    requestWithAuth.headers.set("x-auth-token", env.SECRET);
    return fetch(requestWithAuth);
  },
};

ctx.containerIdを使用することで、異なるインスタンスに対して一意の認証情報を簡単にインジェクトできます:

MySandbox.outboundByHost = {
  "my-internal-vcs.dev": async (
    request: Request,
    env: Env,
    ctx: OutboundHandlerContext,
  ) => {
    const authKey = await env.KEYS.get(ctx.containerId);
    const requestWithAuth = new Request(request);
    requestWithAuth.headers.set("x-auth-token", authKey);
    return fetch(requestWithAuth);
  },
};

トークンがサンドボックスに渡されることはありません。Worker環境で秘密情報をローテーションすると、すべてのリクエストが即座にそれを取得します。

TLSインターセプション

Outbound WorkersがHTTPSトラフィックをインターセプトするようになりました。各サンドボックスインスタンスに対して一意の一時的な認証局(CA)と秘密鍵が作成されます。CAはサンドボックスに配置され、デフォルトで信頼されます。一時的な秘密鍵はコンテナランタイムサイドカープロセスから出ることはなく、インスタンス間で共有されることもありません。

TLSインターセプションが有効な場合、Outbound WorkersはHTTPとHTTPSトラフィックの両方に対して透過的なプロキシとして機能できます。

ホストの許可と拒否

allowedHostsdeniedHostsを使用してアウトバウンドトラフィックを簡単にフィルタリングできます。allowedHostsが設定されると、デフォルト拒否の許可リストになります。両方のプロパティはglobパターンをサポートします。

export class MySandbox extends Sandbox {
  allowedHosts = ["github.com", "npmjs.org"];
}

動的アウトバウンドハンドラー

名前付きアウトバウンドハンドラーを定義し、setOutboundHandler()またはsetOutboundByHost()を使用してランタイムで適用または削除できます。これにより、実行中のサンドボックスを再起動することなく、エグレスポリシーを変更できます。

export class MySandbox extends Sandbox {}

MySandbox.outboundHandlers = {
  allowHosts: async (req: Request, env: Env, ctx: OutboundHandlerContext) => {
    const url = new URL(req.url);
    if (ctx.params.allowedHostnames.includes(url.hostname)) {
      return fetch(req);
    }
    return new Response(null, { status: 403 });
  },
  noHttp: async () => {
    return new Response(null, { status: 403 });
  },
};

Workerからプログラム的にハンドラーを適用:

const sandbox = getSandbox(env.Sandbox, userId);

// セットアップのためにネットワークを開く
await sandbox.setOutboundHandler("allowHosts", {
  allowedHostnames: ["github.com", "npmjs.org"],
});
await sandbox.exec("npm install");

// セットアップ後にロックダウン
await sandbox.setOutboundHandler("noHttp");

ハンドラーはparamsを受け取るため、別々のハンドラー関数を定義することなく、インスタンス毎に動作をカスタマイズできます。

開始方法

これらの機能を使用するには、@cloudflare/containers@0.3.0または@cloudflare/sandbox@0.8.9にアップグレードしてください。詳細については、Sandbox outbound trafficContainer outbound trafficを参照してください。