An instance's vendor credentials sit with one platform service, the front desk: the Credentials entrypoint of the release Worker. A Release never gets a credential. It gets a capability, such as sending a request through a proxy, and the front desk checks on every call that the Release's Scraper holds a grant for it.
Today it hands out four capabilities, all to Worker releases:
proxy:apify, forapifyProxyfrom@scwrap/platform-apifybrowser:browser-useandbrowser:browser-run, forbrowserUseandbrowserRunfrom@scwrap/browserai:workers-ai, forAiGateway.layerConfigfrom@scwrap/ai-cloudflare
How a Run reaches it
- The Run owner, the Durable Object that executes the Run, creates a
Credentialsstub for the Run withctx.exports.Credentials({ props: { scraperId, runId } }). The props name the Release's own Scraper and the Run's result ID. A Release cannot choose or change them. - It provides the stub to the Run as
InstanceCredentials, from@scwrap/domain. apifyProxysends each request to the stub'sproxyFetch(request, route)with the Scraper'sProxyRoute.- The front desk refuses the call unless the grants table lists
proxy:apifyfor that Scraper. Otherwise it builds the Apify Proxy username from the route and the Run's session, as described in Apify Proxy, and passes the request and the proxy address to the proxy relay. - The site's response comes back to the Release. A refusal or a relay failure fails the request with an
HttpClientError, so the Scraper's declared error union does not change.
A browser works the same way: browserUse and browserRun call the stub's browserOpen(provider, options) when a page opens.
- For
browser-use, the front desk checks the grant, creates a Browser Use session with the instance'sBROWSER_USE_API_KEYsecret, the page's country and the provider's timeout, records it with the Run's owner, and returns a session stub. Playwright connects through the stub'sfetch, which the front desk answers with the session's CDP WebSocket. When the page's scope closes, the provider calls the stub'sclose(), and the front desk stops the session, checks that it stopped, and tells the Run owner. The Run owner stops whatever the Release leaves open (Browser Use sessions end with their Run). - For
browser-run, the front desk checks the grant and returns a session stub whosefetchgoes to the release Worker'sBROWSERbinding.@cloudflare/playwrightlaunches Chromium through it.
A refusal fails the open with BrowserError. The Release never sees the Browser Use key or the CDP URL.
Workers AI goes through the stub's aiFetch(request). The front desk checks the grant, refuses any URL outside https://api.cloudflare.com/client/v4/accounts/{account}/ai/ for the instance's CLOUDFLARE_ACCOUNT_ID, replaces the request's Authorization header with the instance's CLOUDFLARE_AI_TOKEN, and sends it. A refusal fails the request as an AiError.
The front desk reads APIFY_PROXY_PASSWORD, APIFY_PROXY_HOSTNAME, APIFY_PROXY_PORT, SCWRAP_PROXY_GROUPS, CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_AI_TOKEN from the release Worker's RELEASE_ENV secret. No Release reads RELEASE_ENV; each reads its own settings.
Browser Use sessions end with their Run
Browser Use bills every minute a session runs, so the Run owner keeps a list of the Browser Use sessions its Run opened, in its Durable Object storage:
- The front desk records each session with the Run owner,
run-<resultId>, before it hands the session to the Release. A Run owner whose Run has ended, or that cannot be reached, refuses the record; the front desk then stops the session at once and the open fails withBrowserError. - A session the Release closes is stopped by the front desk and taken off the list.
- When the Run ends, however it ends (
completed,failed,RunTimeout, stopped or cut off by a forced deploy, or abandoned after its owner was reset), the Run owner stops every session still on the list and checks that each one stopped. - A session that does not stop stays on the list. The Run owner tries again from its alarm after 15 seconds, then 30, 60 and so on, at most 10 minutes apart, until the session stops or its Browser Use timeout has passed. Each attempt is a
RunOwner.stopBrowserSessionsspan withscwrap.browser_sessions.stoppedandscwrap.browser_sessions.left.
So a Release stuck in synchronous code, or one whose finalizers never run, does not keep its Browser Use session after the Run. browser-run sessions are not on the list: Browser Run ends an idle browser by itself.
Each Release in its own sandbox
Every Worker release runs in its own Dynamic Worker, not in the release Worker. The controller leaves its code out of the release Worker's modules, so the platform never imports it.
- Its env is empty. No platform secret or binding enters it.
- Each Run reaches it through one call,
run(input, options). The options hold the Run's result ID, its Scraper's own settings, a front desk stub bound to that Scraper and that Run, and, while the instance exports traces,traces, a stub of the front desk'sTracesentrypoint, with its protocol (Tracing). The Release reads the settings andSCWRAP_RUN_IDthroughConfig. It cannot pose as another Scraper or Run, because the release Worker sets each stub's identity and the Release cannot change it. - Its outbound requests go through the release Worker's
Egressentrypoint, itsglobalOutbound. A raw TCP socket fromcloudflare:socketsopens and is closed at once, without reaching any host. - It is loaded once and reused by the Runs of the same Release, as
<scraper>@<digest>@<sandbox digest>@<sdk digest>, fromreleases/<digest>.mjsand the platform'sscwrap-sdk.mjsin the bucket, each checked against its SHA-256 digest. A failed bucket read is tried twice more, 100 and 200 milliseconds later; a missing or altered artifact is not. A new digest of the Release, of the platform's sandbox code or ofscwrap-sdk.mjsloads a new sandbox. The controller writessdk/<digest>.mjsfor the active platform on every deploy. TheLOADERbinding loads it (Bindings). Runs of one Release can share one isolate at the same time, with its memory and its state at module level; Runs of different Releases never do. - Input and output checks run inside the sandbox, against the Release's own Definition. The release Worker asks it whether an input is valid before starting a Run, and MCP asks it for the Definition's JSON Schemas. The sandbox checks every item against the output schema before sending it; the Run owner checks only that each item is JSON of at most 1 MiB.
The controller refuses an artifact a scwrap CLI before 0.4.0 built (Versions an instance accepts).
Grants
The owner keeps the grants table on the instance, not in a Definition or a Release: SCWRAP_INSTANCE_GRANTS, a JSON object from Scraper IDs to capabilities.
SCWRAP_INSTANCE_GRANTS='{"cbf-bid-publications": ["proxy:apify"], "fff-schedule": ["browser:browser-use"]}'Applying the Stack binds it as the release Worker's GRANTS (Bindings). The Stack refuses an unknown capability and a table that is not such an object. A Scraper missing from the table holds no grants. To revoke a grant, remove it and apply the Stack.
A call without its grant is refused with Scraper <id> holds no grant for <capability>, as a transport failure of that request: an HttpClientError for apifyProxy and Workers AI, a BrowserError for a browser. The Scraper maps it like any other transport failure, usually to UpstreamDown, so the Run's failure cannot tell a missing grant from a site that is down. A build catches it earlier: when the Release's bundle calls the front desk for a capability its Scraper holds no grant for, the build still passes and deploys, and its diagnostics warn, which scwrap deploy prints:
Warning: quotes uses proxy:apify, which the instance's grants table does not give it. The front desk refuses those calls with "Scraper quotes holds no grant for …", which the Release sees as a transport failure, until the instance owner adds the grant to SCWRAP_INSTANCE_GRANTS and applies the Stack.The build finds the calls in the bundle's code, so a Release that bundles a provider it never opens is warned about too.
| Capability | Lets a Release |
|---|---|
proxy:apify | Send HTTP requests through Apify Proxy with apifyProxy. |
browser:browser-use | Open pages in Browser Use sessions with browserUse or browserUseWith. |
browser:browser-run | Open pages in Cloudflare Browser Run with browserRun. |
ai:workers-ai | Ask Workers AI models, such as Clef, through AiGateway.layerConfig. |
Settings
A setting the front desk does not cover, such as the site's own API key or an AI Gateway name, goes in the instance's SCRAPER_SETTINGS secret: a JSON object from Scraper IDs to objects of strings.
{
"cbf-bid-publications": {
"CLOUDFLARE_ACCOUNT_ID": "0123abcd",
"SCWRAP_CAPTCHA_GATEWAY_ID": "scwrap-captcha"
},
"hn-top-stories": { "HN_SERVICE_TOKEN": "…" }
}Each Run gets its own Scraper's entry plus SCWRAP_RUN_ID as Config, and nothing of another Scraper's entry. A Scraper missing from the table gets no settings. A value that is not such an object fails every Run, without naming the value. Set it with scwrap secrets set SCRAPER_SETTINGS, which needs an unlimited deployer token, and store the same value under SCWRAP_INSTANCE_SCRAPER_SETTINGS so a fresh install of the stage gets it.
An instance installed before SCRAPER_SETTINGS existed has no such secret. Until it is set, every Run gets RELEASE_ENV without the keys the front desk holds, as before (Known gaps).
The proxy relay
A Worker cannot speak TLS with a site through a CONNECT tunnel: startTls sends no SNI (workerd #6903). So the front desk sends proxied requests through the proxy relay, the release Worker's ProxyRelay Durable Object class with its own Container application.
- The Container runs a small Node HTTP server and no Scraper code. For each request it opens a
CONNECTtunnel through the proxy and speaks TLS with the site's own name, or sendshttp:requests to the proxy in absolute form. - Only the front desk reaches it, through the
PROXY_RELAYbinding. It has no route and no public address, and it gets the proxy address with each request, so it holds no credential at rest. - One relay serves the whole instance, one per platform version: a
basicContainer (1 GiB, 1/4 vCPU) taking up to 64 requests at a time. It stops 10 minutes after its last request.
Source
- credentials.ts: the grant check, each Scraper's settings, and the proxy, browser and AI capabilities
- proxy-relay.ts: the relay's Node server
- runtime-entry.ts: the
Credentials,Traces,BrowserSessionandEgressentrypoints, the sandbox loader and theProxyRelayclass - sandbox-entry.ts and release-sandbox.ts: the code that runs a Release inside its sandbox
- release-contract.ts: input and schema checks for both kinds of Release
- instance-grants.ts: how the Stack checks and binds the grants table