Skip to content

feat: tunnel example#741

Open
james-rl wants to merge 2 commits intomainfrom
james/ex-tunnel
Open

feat: tunnel example#741
james-rl wants to merge 2 commits intomainfrom
james/ex-tunnel

Conversation

@james-rl
Copy link
Contributor

@james-rl james-rl commented Mar 4, 2026

User description

⚠️ PR Title Must Follow Conventional Commits

Format: feat[optional scope]: <description>

Examples: feat: add new SDK method · feat(storage): support file uploads · feat!: breaking API change


Description

Motivation

Adds an example using tunnels

Changes

Testing

  • Unit tests added
  • Integration tests added
  • Smoke Tests added/updated
  • Tested locally

Breaking Changes

Checklist

  • PR title follows Conventional Commits format (feat: or feat(scope):)
  • Documentation updated (if needed)
  • Breaking changes documented (if applicable)

CodeAnt-AI Description

Add runnable Devbox Tunnel example with HTTP server and tunnel access

What Changed

  • Added a new example that creates a devbox, starts an HTTP server inside it, enables a tunnel, and makes an HTTP request from the local machine through the tunnel to verify access
  • Registered the new example in the examples registry so it appears in CLI discovery and runs
  • Updated the examples documentation with a dedicated section showing workflow, prerequisites, run and test commands

Impact

✅ Runnable tunnel example for testing external access
✅ Easier verification of HTTP services running in devboxes
✅ Clearer documentation for creating and using devbox tunnels

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

@james-rl james-rl requested a review from dines-rl March 4, 2026 01:00
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Mar 4, 2026

CodeAnt AI is reviewing your PR.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai bot added the size:L This PR changes 100-499 lines, ignoring generated files label Mar 4, 2026
@james-rl james-rl requested a review from tode-rl March 4, 2026 01:01
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Mar 4, 2026

Nitpicks 🔍

🔒 No security issues identified
⚡ Recommended areas for review

  • Incomplete cleanup (race / leak)
    The code starts a long-running HTTP server via devbox.cmd.execAsync but only calls serverExecution.kill() after the fetch. If an exception occurs before the kill (for example, if fetch fails), the server may remain running until the devbox is shutdown. Wrap operations in try/finally or register a dedicated cleanup step to ensure the server process is always terminated.

  • Global fetch
    The example uses fetch(tunnelUrl) from the Node-side example. Some execution environments (test harnesses, older Node versions, or custom runtimes) may not provide a global fetch. This can cause the example to fail at runtime. Consider importing a fetch polyfill or explicitly using a provided HTTP client.

  • Auto-generated file edit
    examples/registry.ts contains a header that it is auto-generated. The PR adds an import and a registry entry by editing this file directly — this change could be overwritten by the generator script. Confirm the generator was updated, or make the change in the generator so it persists.

  • Brittle assertion
    The check that the response contains 'Directory listing' is fragile: different Python versions, locales, directory contents (index.html present), or server implementations may return different HTML/strings. This may lead to flaky test/example results. Prefer validating status codes, existence of expected files, or checking for HTML tags instead of a specific phrase.

@codeant-ai
Copy link
Contributor

codeant-ai bot commented Mar 4, 2026

CodeAnt AI finished reviewing your PR.

// Enable a tunnel to expose the HTTP server
// For authenticated tunnels, use auth_mode: 'authenticated' and include the auth_token
// in your requests via the Authorization header: `Authorization: Bearer ${tunnel.auth_token}`
const tunnel = await devbox.net.enableTunnel({ auth_mode: 'open' });
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be on create

);

// Give the server a moment to start
await new Promise((resolve) => setTimeout(resolve, SERVER_STARTUP_DELAY_MS));
Copy link
Contributor

Choose a reason for hiding this comment

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

You could look for a log? or do a while loop to hit the tunnel

const tunnel = await devbox.net.enableTunnel({ auth_mode: 'open' });

// Get the tunnel URL for the server port
const tunnelUrl = await devbox.getTunnelUrl(HTTP_SERVER_PORT);
Copy link
Contributor

Choose a reason for hiding this comment

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

should happen at the beginning after create

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

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants