Method signature

public getHost(port: number): string

Parameters

ParameterTypeRequiredDescription
portnumberYesThe port number to get the host URL for

Return value

TypeDescription
stringThe host URL that can be used to access the specified port in the sandbox

Examples

Get Host for Web Server

import { VibeKit } from 'vibekit';

const vibekit = new VibeKit(config);

// Start a web server on port 3000
await vibekit.executeCommand('npm run dev -- --port 3000', {
  background: true
});

// Get the host URL for the web server
const hostUrl = vibekit.getHost(3000);
console.log('Web server accessible at:', hostUrl);
// Output: https://3000-sandbox-id.e2b.dev

Get Host for API Server

// Start an API server
await vibekit.executeCommand('python -m http.server 8080', {
  background: true
});

// Get the host URL for the API
const apiUrl = vibekit.getHost(8080);
console.log('API server accessible at:', apiUrl);
// Output: https://8080-sandbox-id.e2b.dev

Get Host for Database Connection

// Start a database server
await vibekit.executeCommand('mongod --port 27017', {
  background: true
});

// Get the host URL for database access
const dbHost = vibekit.getHost(27017);
console.log('Database accessible at:', dbHost);
// Output: https://27017-sandbox-id.e2b.dev

Error handling

The method throws errors in the following cases:

  • E2B sandbox not active: When called without an active E2B sandbox environment
  • Unsupported sandbox: When called with non-E2B sandbox environments (Daytona, FlyIO, Modal)
  • Invalid port: When the port number is invalid or out of range
try {
  const hostUrl = vibekit.getHost(3000);
  console.log('Host URL:', hostUrl);
} catch (error) {
  if (error.message.includes('E2B')) {
    console.error('E2B sandbox required for getHost functionality');
  } else if (error.message.includes('port')) {
    console.error('Invalid port number provided');
  } else {
    console.error('Failed to get host URL:', error.message);
  }
}

Sandbox compatibility

Sandbox TypeSupportedNotes
E2B✅ YesFull support with automatic URL generation
Daytona❌ NoPort forwarding not yet implemented
FlyIO❌ NoPort forwarding not yet implemented
Modal❌ NoPort forwarding not yet implemented

Use cases

  • Web Development: Access development servers running in the sandbox
  • API Testing: Get URLs for API servers to test endpoints
  • Database Access: Connect to databases running in the sandbox
  • Microservices: Access multiple services running on different ports
  • Live Previews: Generate URLs for real-time preview of web applications

Notes

  • E2B Only: This method is exclusively available for E2B sandbox environments
  • Automatic URL Generation: E2B automatically generates secure HTTPS URLs for exposed ports
  • Real-time Access: URLs are immediately accessible once the service starts on the specified port
  • Security: All generated URLs use HTTPS and are scoped to the specific sandbox instance
  • Port Range: Standard port ranges (1-65535) are supported
  • No Port Validation: The method doesn’t validate if a service is actually running on the specified port