E2B Dashboard

repository·main·Indexed 41 days ago

https://github.com/e2b-dev/dashboard

An open-source dashboard for managing and monitoring self-hosted E2B infrastructure. It enables teams to manage sandboxes and templates using a single team API key, providing tools for local development, Docker deployment, and server-side action management via tRPC and next-safe-action.

Tokens
10.9K
Snippets
32
Records
59
Agent score
51%

What's inside E2B Dashboard

  1. How authentication works in E2B Dashboard

    main

    The dashboard uses a single team API key for authentication. It does not use user accounts or external auth providers.

    1. Via UI: Visiting / presents a form to enter the key. The key is validated against the infra-api and stored in an httpOnly e2b_api_key cookie. All upstream requests are made server-side using the X-API-Key header, ensuring the key is never exposed to client-side JavaScript.
    2. Via Environment Variable: Setting E2B_API_KEY at server start enables single-user mode. In this mode, the login form and sign-out options are automatically hidden.
  2. Set up E2B Dashboard for local development

    main

    To run the E2B Dashboard locally, ensure you have a running E2B infrastructure deployment and a team API key (starting with e2b_).

    1. Clone the repository:
      git clone https://github.com/e2b-dev/dashboard.git
      cd dashboard
    2. Install dependencies using Bun:
      bun install
    3. Configure environment variables: Copy the example file and set PUBLIC_E2B_DOMAIN to point to your infrastructure domain.
      cp .env.example .env
      # Edit .env to set PUBLIC_E2B_DOMAIN
    4. Start the development server:
      bun run dev
    5. Authenticate: Open http://localhost:3000 in your browser and enter your team API key.
    git clone https://github.com/e2b-dev/dashboard.git
    cd dashboard
    bun install
    cp .env.example .env
    bun run dev
  3. Run E2B Dashboard in a Docker container

    main

    The dashboard can be deployed as a self-contained Docker image. You must provide the PUBLIC_E2B_DOMAIN at runtime to point the dashboard to your E2B cluster.

    Build and run locally:

    docker build -t e2b-dashboard .
    docker run --rm -p 3001:3001 \
      -e PUBLIC_E2B_DOMAIN=your-domain.com \
      e2b-dashboard

    Use a published release:

    docker run --rm -p 3001:3001 us-docker.pkg.dev/e2b-artifacts/dashboard/dashboard:vX.Y.Z

    Note on Ports: The default port is 3001. This avoids conflicts with the E2B API, which typically uses port 3000 when sharing a host network.

  4. How to use public and protected procedures in tRPC

    main

    The dashboard uses two primary tRPC procedure types to manage access control and observability:

    1. publicProcedure: Use this for routes that do not require authentication. It automatically includes telemetry middleware to track request timing.
    2. protectedProcedure: Use this for routes that require authentication (via team API key in cookies or the E2B_API_KEY environment variable). It includes telemetry and the authMiddleware to verify the user's identity.

    Important Telemetry Rule: Telemetry middleware must always be used as a pair to ensure accurate timing and context collection. startTelemetryMiddleware must be the first middleware in the chain, and endTelemetryMiddleware must be placed after all domain-specific middlewares (like authMiddleware).

    // Example of defining a new procedure using these patterns
    import { publicProcedure, protectedProcedure } from '@/core/server/trpc/procedures';
    
    // A public route
    export const myPublicRoute = publicProcedure
      .input(z.string())
      .query(({ input }) => {
        return { message: `Hello, ${input}` };
      });
    
    // A protected route
    export const myProtectedRoute = protectedProcedure
      .input(z.object({ id: z.string() }))
      .mutation(({ input, ctx }) => {
        // ctx.auth is available here due to authMiddleware
        return { success: true };
      });
  5. Configure E2B Dashboard environment variables

    main

    The dashboard uses several environment variables to connect to your infrastructure. PUBLIC_E2B_DOMAIN is required; missing or blank values will prevent startup.

    VariableTypePurpose
    PUBLIC_E2B_DOMAINruntimeRequired. The E2B cluster domain. Used to derive https://api.<domain> and https://dashboard-api.<domain>.
    PUBLIC_SANDBOX_URLper requestOptional. Base URL for sandbox traffic. Use this for local sandbox proxies (e.g., http://127.0.0.1:3002).
    E2B_INFRA_API_URLserver startOptional. Overrides the derived https://api.<domain> URL.
    E2B_DASHBOARD_API_URLserver startOptional. Overrides the derived https://dashboard-api.<domain> URL.
    DASHBOARD_COOKIE_SECUREserver startfalse for plain-http installs. Defaults to true in production.
    E2B_API_KEYserver startPre-authenticates the deployment (single-user mode). Hides the login form.
    PORTserver startThe port the server listens on (default 3001).
    HOSTNAMEserver startThe hostname the server listens on (default 0.0.0.0).

    Important: All URLs must include the protocol (http:// or https://).

  6. Configure Sandbox Workload Identity (IAM)

    main

    You can enable workload identity for a sandbox by providing a non-empty, valid tokens map in the SandboxIam configuration. This is done via the tokens field, which is a map of user-chosen names to SandboxIamToken definitions.

    const iamConfig: SandboxIam = {
      tokens: {
        'my-token-name': {
          audience: 'my-audience',
          tokenType: 'some-type'
        }
      }
    };
  7. How API key authentication works in the E2B Dashboard

    main

    The E2B Dashboard uses two primary methods to authenticate requests and identify the team API key:

    1. Environment Variable (E2B_API_KEY): In single-user self-hosted deployments, setting this environment variable provides permanent authentication. When this is set, the dashboard skips the API key entry form and hides all 'change API key' UI elements.
    2. HTTP-only Cookie (e2b_api_key): For standard deployments, the API key is provided via a key form on the root path (/) and stored in a secure, httpOnly cookie.

    If E2B_API_KEY is present, it takes precedence over the cookie.

  8. Configure cookie security via DASHBOARD_COOKIE_SECURE

    main

    The security of cookies (the secure flag) is determined by the DASHBOARD_COOKIE_SECURE environment variable.

    • If DASHBOARD_COOKIE_SECURE is set to 'true', cookies will always be marked as secure.
    • If DASHBOARD_COOKIE_SECURE is undefined, the dashboard defaults to secure: true in production environments and secure: false in other environments (like local development).

    This setting affects all cookies managed by the dashboard, including the e2b_api_key.

  9. Configure Sandbox Network and Egress

    main

    Sandboxes can be configured with specific network rules and egress settings.

    SandboxNetworkConfig

    Used to define how a sandbox interacts with the network:

    • allowPublicTraffic: Boolean. If true, sandbox URLs are accessible with authentication.
    • allowOut: List of allowed destinations (CIDR blocks, IPs, or domain names). Allowed entries take precedence.
    • denyOut: List of denied CIDR blocks or IPs. Domain names are not supported for deny rules.
    • egressProxy: Configuration for a SOCKS5 proxy (SandboxEgressProxyConfig).
    • rules: Per-domain transform rules (SandboxNetworkRule) applied to matching egress HTTP/HTTPS requests.
    • allow_internet_access: Boolean. If false, behaves like specifying denyOut: 0.0.0.0/0.

    SandboxEgressProxyConfig

    • address: SOCKS5 proxy address in host:port format.
    • username: Optional SOCKS5 username.
    • password: Optional SOCKS5 password.
  10. Configure New Sandbox creation

    main

    When creating a new sandbox using the NewSandbox schema, you can specify several configuration options to control its lifecycle, networking, and identity:

    • templateID: The identifier of the required template.
    • timeout: Time to live in seconds (defaults to 15).
    • autoPause: Automatically pause the sandbox after the timeout (defaults to false).
    • autoPauseMemory: If true, a full memory snapshot is taken. If false, only the filesystem is persisted, resulting in a cold-boot (reboot) upon resumption. (defaults to true).
    • autoResume: Configuration for automatic resumption.
    • secure: Secure all system communication with the sandbox.
    • allow_internet_access: If false, behaves like specifying denyOut to 0.0.0.0/0 in network config.
    • network: SandboxNetworkConfig settings.
    • metadata: Custom metadata.
    • envVars: Environment variables.
    • mcp: MCP configuration.
    • iam: SandboxIam configuration for workload identity.
    • volumeMounts: List of SandboxVolumeMount objects.
    // Example NewSandbox configuration object
    const newSandbox: NewSandbox = {
      templateID: 'my-template-id',
      timeout: 30,
      autoPause: true,
      autoPauseMemory: false,
      allow_internet_access: true,
      metadata: { key: 'value' }
    };
  11. Configure Template Builds

    main

    Templates can be built using several request formats. For version 3 builds (TemplateBuildRequestV3), use the name field which can include a tag (e.g., "my-template:v1").

    Key build configuration options include:

    • fromImage: Image to use as a base.
    • fromTemplate: Template to use as a base.
    • fromImageRegistry: Registry authentication (supports aws, gcp, or registry types).
    • steps: A list of TemplateStep objects to execute.
    • startCmd: Command to execute after build.
    • readyCmd: Command to execute after build to check readiness.
    • force: Whether to force the build regardless of cache.
    // Example TemplateBuildStartV2
    const buildRequest: TemplateBuildStartV2 = {
      fromImage: 'ubuntu:latest',
      steps: [
        { type: 'run', args: ['apt-get', 'update'], force: true }
      ],
      startCmd: 'python app.py',
      readyCmd: 'curl localhost:8080'
    };
  12. Deprecated environment variables for E2B Dashboard

    main

    If you are upgrading, ensure you rename the following legacy variables to their current counterparts. The dashboard will report validation errors if deprecated variables are still set.

    Deprecated variableReplacement
    NEXT_PUBLIC_E2B_DOMAINPUBLIC_E2B_DOMAIN
    NEXT_PUBLIC_INFRA_API_URLE2B_INFRA_API_URL
    NEXT_PUBLIC_DASHBOARD_API_URLE2B_DASHBOARD_API_URL
    NEXT_PUBLIC_E2B_SANDBOX_URL / E2B_SANDBOX_URLPUBLIC_SANDBOX_URL