E2B icon indicating copy to clipboard operation
E2B copied to clipboard

e2b sandbox host URL not wokring

Open ppramanik62 opened this issue 1 year ago • 5 comments

e2b.Dockerfile

FROM node:20-slim

# Prevent interactive prompts and set timezone
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=UTC
ENV NODE_ENV=development

# Install system dependencies
RUN apt-get update && apt-get install -y curl && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /home/user/code

# Initialize Vite project as root (Docker build context)
RUN npm create vite@latest . -- --template vanilla

# Copy start script (with correct permissions)
COPY scripts/start-server.sh /home/user/start-server.sh
RUN chmod +x /home/user/start-server.sh

# Move project to home dir and clean up
RUN mv /home/user/code/* /home/user/ && rm -rf /home/user/code
RUN npm install

# Set default shell
CMD ["/bin/bash"]

start-server.sh

#!/bin/bash

function ping_server() {
  counter=0
  response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:5173")
  while [[ ${response} -ne 200 ]]; do
    let counter++
    if (( counter % 20 == 0 )); then
      echo "Waiting for dev server to start..."
      sleep 0.1
    fi

    response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:5173")
  done
  echo "Dev server is ready!"
}

echo "Starting development server..."

ping_server &
cd /home/user && npm run dev -- --port 5173

I've published the template to E2B dashboard. But while navigating to the sandbox host url, I'm getting this error

Image

ppramanik62 avatar Jul 02 '25 19:07 ppramanik62

Hey, make sure you bind the port to 0.0.0.0 - binding on localhost won't expose the port (anymore)

mishushakov avatar Jul 02 '25 19:07 mishushakov

Then this error shows up

Blocked request. This host ("5173-<sandbox-id>.e2b.app") is not allowed.
To allow this host, add "5173-<sandbox-id>.e2b.app" to `server.allowedHosts` in vite.config.js.

vite.config.ts

server: {
      allowedHosts: [
          ".e2b.app",
      ],
},

still the same error is showing

ppramanik62 avatar Jul 03 '25 06:07 ppramanik62

Hey, here's an example vite template that should be working: template.zip

mishushakov avatar Jul 03 '25 10:07 mishushakov

Thanks for the help and guidance. Sandbox and the host URL is working fine now.

ppramanik62 avatar Jul 03 '25 11:07 ppramanik62