Skip to content

Consolidate egress configuration across backends - #88

Open
aron-cf wants to merge 5 commits into
mainfrom
worker-shell-internet
Open

Consolidate egress configuration across backends#88
aron-cf wants to merge 5 commits into
mainfrom
worker-shell-internet

Conversation

@aron-cf

@aron-cf aron-cf commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

This change gives the container, Worker shell, and Worker JavaScript backends one way to configure ambient network access. Previously the container always had direct Internet access, while the Dynamic Worker backends used backend-specific controls. The Worker shell's custom fetcher option also mixed runtime creation with outbound network policy.

The shared WorkspaceEgressPolicy supports three modes. none blocks ambient network access and is the default, direct uses the backend's native Internet access, and http-gateway sends HTTP and HTTPS requests through a host-provided Fetcher. The gateway mode does not promise portable interception of arbitrary TCP connections. Trusted host operations, including Git and artifact network access, remain controlled by their existing capability options rather than by ambient egress.

A policy can be defined once and passed to any backend:

import type { WorkspaceEgressPolicy } from "@cloudflare/computer";

const blockedEgress = { mode: "none" } satisfies WorkspaceEgressPolicy;
const directEgress = { mode: "direct" } satisfies WorkspaceEgressPolicy;

const gatewayEgress = (gateway: Fetcher) =>
  ({
    mode: "http-gateway",
    gateway,
    revision: "allowlist-v1",
  }) satisfies WorkspaceEgressPolicy;

For a container backend, pass the policy alongside the container host and workspace reference. Container callbacks use an authenticated WorkspaceProxy, so the Worker must continue to export that entrypoint. Existing applications that need the previous direct Internet behavior must now opt in with directEgress.

import { WorkspaceProxy } from "@cloudflare/computer";
import { CloudflareContainerBackend } from "@cloudflare/computer/backends/container";

export { WorkspaceProxy };

const backend = new CloudflareContainerBackend({
  container: () => this,
  workspace: {
    binding: "WorkspaceAgent",
    id: this.ctx.id.toString(),
  },
  egress: gatewayEgress(this.env.EGRESS_GATEWAY),
});

For the managed Worker shell, the same policy is applied before the Loader creates or selects the shell isolate. The policy identity is included in the Loader cache key, and revision lets an application choose when a gateway configuration may reuse an isolate.

import { WorkspaceServiceProxy } from "@cloudflare/computer";
import { WorkerShellBackend } from "@cloudflare/computer/backends/worker-shell";

export { WorkspaceServiceProxy };

const backend = new WorkerShellBackend({
  source: {
    type: "loader",
    loader: this.env.LOADER,
    workspace: {
      binding: "WorkspaceAgent",
      id: this.ctx.id.toString(),
    },
    ctx: this.ctx,
  },
  egress: blockedEgress,
});

Applications that create the shell runtime through a service binding, dispatch namespace, broker, or pool can use the explicit external runtime source. The source receives the policy before it creates or selects the runtime, and is responsible for enforcing it.

const backend = new WorkerShellBackend({
  source: {
    type: "external-runtime",
    async connect({ egress }) {
      return createShellRuntime({ egress });
    },
  },
  egress: directEgress,
});

For Worker JavaScript, the policy maps directly to the Dynamic Worker Loader's outbound setting. The existing globalOutbound option remains available for compatibility, but it cannot be combined with egress.

import { WorkerJavaScriptBackend } from "@cloudflare/computer/backends/worker-javascript";

const backend = new WorkerJavaScriptBackend({
  loader: this.env.LOADER,
  egress: gatewayEgress(this.env.EGRESS_GATEWAY),
  allowGitNetwork: false,
  allowArtifactNetwork: false,
});

The change is covered by backend tests for all three modes, Worker shell source and Loader lifecycle tests, container callback authentication tests, and proxy forwarding tests. The container-based examples opt into direct egress so their existing behavior does not change.

Reviewers can verify the change with:

npm run format
npx biome check .
npm run typecheck
npm run build --workspace @cloudflare/computer
npm test --workspace @cloudflare/computer
npm test --workspace @cloudflare/example-think-compare-runtimes

Reference documentation and a production example for the external Worker shell runtime remain follow-up work.

aron-cf added 5 commits August 7, 2026 15:26
Default ambient execution network access to blocked across containers and
Dynamic Workers. Support explicit direct access or an HTTP gateway while
keeping host Git and artifact capabilities independent.

Route container gateway requests through authenticated workspace callbacks
and scope Worker shell loader identities by policy. Replace the custom shell
fetcher path with typed loader and external runtime sources.
@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

馃 Changeset detected

Latest commit: 2d47263

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/computer Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Thanks for your interest in Cloudflare Computer.

This repository does not accept unsolicited pull requests. Please use one of the accepted contribution paths instead:

If a maintainer asked you to open this pull request, they can add the allow-pr label and reopen it.

@github-actions github-actions Bot closed this Aug 7, 2026
@aron-cf aron-cf added the allow-pr Allow a PR to remain open. label Aug 7, 2026
@aron-cf aron-cf reopened this Aug 7, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@cloudflare/computer@88

commit: 2d47263

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

allow-pr Allow a PR to remain open.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant