Skip to content

[Sandbox] Add guide to document tunnel auth#31229

Draft
aron-cf wants to merge 4 commits into
productionfrom
sandbox-tunnel-auth
Draft

[Sandbox] Add guide to document tunnel auth#31229
aron-cf wants to merge 4 commits into
productionfrom
sandbox-tunnel-auth

Conversation

@aron-cf
Copy link
Copy Markdown
Contributor

@aron-cf aron-cf commented Jun 4, 2026

Summary

This adds a guide for authenticating Sandbox SDK tunnels. Or, more specifically configuring Cloudflare Access on Cloudflare Tunnel resources created by the Sandbox SDK.

Documentation checklist

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2026

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
/src/content/docs/sandbox/ @whoiskatrin, @ghostwriternr, @scuffi, @aron-cf, @thomasgauvin, @cloudflare/product-owners, @cloudflare/ai-agents

aron-cf added 2 commits June 4, 2026 09:11
Use getProcess() with a stable processId before startProcess() so the
Worker fetch handler does not spawn a duplicate server on every request.
Also wait for the port to be ready before creating the tunnel.
- Simplify env var bullet to CLOUDFLARE_API_TOKEN and link to Tunnels.
- Reorder steps so Access auth (service token, application) is set up
  before the tunnel is created.
- Drop the public-hostname interim paragraph and the editorialising
  ', which is rarely what an automation client wants' clause.
- Reframe Application domain as: create the policy first, then add more
  domains to the same application.
Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 style issues need addressing before merge.

LOWprotect-tunnels-with-access.mdx:55 — Use 'refer to' instead of 'see'.
LOWprotect-tunnels-with-access.mdx:81 — Use '(Optional)' instead of 'Optional:'.
LOWprotect-tunnels-with-access.mdx:112 — Use 'Refer to' instead of 'See'.
LOWprotect-tunnels-with-access.mdx:116 — Use 'Refer to' instead of 'See' and 'refer to' instead of 'see'.
MEDIUMprotect-tunnels-with-access.mdx — Wrap the multi-step procedure in <Steps> per the procedures style guide.
LOWexpose-services.mdx:18 — Use 'refer to' instead of 'see'.

```
</TypeScriptExample>

`startProcess` resolves when the process starts, not when it is listening. In real code, wait for the port to be ready before calling `tunnels.get()` — see [Expose services](/sandbox/guides/expose-services/) for an example.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 'refer to' instead of 'see':

Suggested change
`startProcess` resolves when the process starts, not when it is listening. In real code, wait for the port to be ready before calling `tunnels.get()`see [Expose services](/sandbox/guides/expose-services/) for an example.
`startProcess` resolves when the process starts, not when it is listening. In real code, wait for the port to be ready before calling `tunnels.get()`refer to [Expose services](/sandbox/guides/expose-services/) for an example.

- **Action**: `Service Auth` (see [policy actions](/cloudflare-one/access-controls/policies/#service-auth)). If you use `Allow` here, Access will redirect unauthenticated requests to an identity provider login page instead of returning an error, which is rarely what an automation client wants.
- **Include**: `Service Token` → the token created in step 2.

Optional: add a second `Allow` policy (for example, `Emails ending in @your-company.com`) so engineers can hit the URL in a browser via the identity provider flow for debugging.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use '(Optional)' instead of 'Optional:':

Suggested change
Optional: add a second `Allow` policy (for example, `Emails ending in @your-company.com`) so engineers can hit the URL in a browser via the identity provider flow for debugging.
(Optional) Add a second `Allow` policy (for example, `Emails ending in @your-company.com`) so engineers can hit the URL in a browser via the identity provider flow for debugging.


### Single custom header

If the calling system can only set one header (for example, a SaaS integration that exposes a single `Authorization` field), configure the Access application to read both values from one header. See [Authenticate with a single header](/cloudflare-one/access-controls/service-credentials/service-tokens/#authenticate-with-a-single-header).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 'Refer to' instead of 'See':

Suggested change
If the calling system can only set one header (for example, a SaaS integration that exposes a single `Authorization` field), configure the Access application to read both values from one header. See [Authenticate with a single header](/cloudflare-one/access-controls/service-credentials/service-tokens/#authenticate-with-a-single-header).
If the calling system can only set one header (for example, a SaaS integration that exposes a single `Authorization` field), configure the Access application to read both values from one header. Refer to [Authenticate with a single header](/cloudflare-one/access-controls/service-credentials/service-tokens/#authenticate-with-a-single-header).


### Session cookie reuse

If your Access application has at least one `Allow` policy in addition to Service Auth (see step 3), Access returns a `CF_Authorization` cookie on the first authenticated request, and subsequent requests on the same hostname can send the cookie instead of the headers. Service-Auth-only applications do not honor the cookie — every request must carry the headers. See [Authorization cookie](/cloudflare-one/access-controls/applications/http-apps/authorization-cookie/) and [Subsequent requests](/cloudflare-one/access-controls/service-credentials/service-tokens/#subsequent-requests).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 'Refer to' instead of 'See' and 'refer to' instead of 'see':

Suggested change
If your Access application has at least one `Allow` policy in addition to Service Auth (see step 3), Access returns a `CF_Authorization` cookie on the first authenticated request, and subsequent requests on the same hostname can send the cookie instead of the headers. Service-Auth-only applications do not honor the cookie — every request must carry the headers. See [Authorization cookie](/cloudflare-one/access-controls/applications/http-apps/authorization-cookie/) and [Subsequent requests](/cloudflare-one/access-controls/service-credentials/service-tokens/#subsequent-requests).
If your Access application has at least one `Allow` policy in addition to Service Auth (refer to step 3), Access returns a `CF_Authorization` cookie on the first authenticated request, and subsequent requests on the same hostname can send the cookie instead of the headers. Service-Auth-only applications do not honor the cookie — every request must carry the headers. Refer to [Authorization cookie](/cloudflare-one/access-controls/applications/http-apps/authorization-cookie/) and [Subsequent requests](/cloudflare-one/access-controls/service-credentials/service-tokens/#subsequent-requests).


:::note[Alternative: quick tunnels]
If you only need a public URL for development or a `.workers.dev` deployment, [`sandbox.tunnels`](/sandbox/api/tunnels/) returns a `*.trycloudflare.com` URL without DNS setup. For production, follow this guide and use `exposePort()` with a custom domain.
If you only need a public URL for development or a `.workers.dev` deployment, [`sandbox.tunnels`](/sandbox/api/tunnels/) returns a `*.trycloudflare.com` URL without DNS setup. For production, follow this guide and use `exposePort()` with a custom domain. To require authentication on a tunnel before requests reach the sandbox, see [Protect tunnels with Cloudflare Access](/sandbox/guides/protect-tunnels-with-access/).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 'refer to' instead of 'see':

Suggested change
If you only need a public URL for development or a `.workers.dev` deployment, [`sandbox.tunnels`](/sandbox/api/tunnels/) returns a `*.trycloudflare.com` URL without DNS setup. For production, follow this guide and use `exposePort()` with a custom domain. To require authentication on a tunnel before requests reach the sandbox, see [Protect tunnels with Cloudflare Access](/sandbox/guides/protect-tunnels-with-access/).
If you only need a public URL for development or a `.workers.dev` deployment, [`sandbox.tunnels`](/sandbox/api/tunnels/) returns a `*.trycloudflare.com` URL without DNS setup. For production, follow this guide and use `exposePort()` with a custom domain. To require authentication on a tunnel before requests reach the sandbox, refer to [Protect tunnels with Cloudflare Access](/sandbox/guides/protect-tunnels-with-access/).

@ask-bonk ask-bonk Bot added triage Waiting for a docs team review. content:new Request for new/missing content labels Jun 4, 2026
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Jun 4, 2026

Posted a review on PR #31229 and applied labels triage and content:new.

What changed

  • Added src/content/docs/sandbox/guides/protect-tunnels-with-access.mdx — a how-to guide for locking down Sandbox SDK named tunnels with a Cloudflare Access service token and self-hosted Access application.
  • Modified src/content/docs/sandbox/guides/expose-services.mdx — added a cross-link to the new guide in the “Alternative: quick tunnels” note.

Issues flagged

Severity File Issue
LOW protect-tunnels-with-access.mdx:55 “see [Expose services]” → “refer to [Expose services]”
LOW protect-tunnels-with-access.mdx:81 “Optional: add” → “(Optional) Add”
LOW protect-tunnels-with-access.mdx:112 “See [Authenticate …]” → “Refer to [Authenticate …]”
LOW protect-tunnels-with-access.mdx:116 “See [Authorization …]” → “Refer to [Authorization …]” and “(see step 3)” → “(refer to step 3)”
LOW expose-services.mdx:18 “see [Protect tunnels …]” → “refer to [Protect tunnels …]”
MEDIUM protect-tunnels-with-access.mdx The multi-step procedure (steps 1–5) should be wrapped in <Steps> per the procedures style guide.

No build breakers, broken links, or invalid frontmatter were found. The Render partial, TypeScriptExample usage, and internal links all look correct.

github run

- Add an APIRequest example showing how to PUT the Access application
  with an updated destinations array to add a hostname programmatically.
- Wrap the verify and header-pair curl snippets in the CURL component
  to match the convention used elsewhere in the docs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

content:new Request for new/missing content product:sandbox size/m triage Waiting for a docs team review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants