Skip to content

Expose Preview URLs and Sandbox Metadata via Environment Variables #1989

Open
@Julian-AT

Description

@Julian-AT

Is your feature request related to a problem? Please describe.

Currently, Daytona provides preview URLs and tokens through SDK methods like sandbox.get_preview_link(port). However, this information isn't readily accessible within the running container or sandbox environment. This limitation poses challenges for applications that need to:

  • Display or utilize their own preview URL dynamically.
  • Communicate this URL to frontend clients or external services.
  • Integrate with frameworks (e.g., Next.js, Vite) that rely on environment variables for runtime configuration.
  • Facilitate CI/CD workflows that depend on consistent environment variable patterns.

Without this capability, the only way to archive this goal are workarounds like hardcoding values or modifying entrypoint scripts, which can be error-prone and less maintainable.

Describe the solution you'd like

Introduce a standardized set of environment variables within the sandbox or container that expose essential runtime information. For instance:

  • DAYTONA_PUBLIC_PREVIEW_URL: The public preview URL for the application.
  • DAYTONA_PREVIEW_TOKEN: The associated token for authenticated access, if applicable.
  • DAYTONA_SANDBOX_ID: The unique identifier for the current sandbox.
  • DAYTONA_PORT_<PORT_NUMBER>_URL: The preview URL for a specific port, e.g., DAYTONA_PORT_3000_URL.

To distinguish between public and internal variables, adopt a naming convention similar to Next.js, where variables prefixed with DAYTONA_PUBLIC_ are safe to expose to client-side code.

These environment variables should be automatically injected into the container's environment at runtime, ensuring seamless access for applications and scripts.

Describe alternatives you've considered

  • SDK Methods: Using SDK methods like sandbox.get_preview_link(port) requires additional code and isn't accessible within the container without external tooling.

  • Entrypoint Scripts: Modifying entrypoint scripts to fetch and export these values adds complexity and potential points of failure.

  • Manual Configuration: Hardcoding URLs or tokens is brittle and doesn't adapt well to dynamic environments.

These approaches lack the elegance and reliability of environment variables that are automatically managed by the platform.

Additional context

Many modern platforms and frameworks utilize environment variables to pass runtime configuration:

  • Vercel: Provides VERCEL_URL and VERCEL_ENV for runtime context.
  • Next.js: Uses the NEXT_PUBLIC_ prefix to expose variables to the browser.
  • Docker: Allows environment variable injection via docker run -e.

For example, in a Daytona sandbox running a Flask app on port 3000, the following environment variables could be set:

DAYTONA_PUBLIC_PREVIEW_URL=https://3000-sandbox-abc123.h7890.daytona.work
DAYTONA_PUBLIC_PREVIEW_TOKEN=vg5c0ylmcimr8b_v1ne0u6mdnvit6gc0
DAYTONA_SANDBOX_ID=sandbox-abc123
DAYTONA_PORT_3000_URL=https://3000-sandbox-abc123.h7890.daytona.work

Let me know your thoughts about this topic 😄

Cheers,
Julian S.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions