getHost
Get the host URL for a specific port in the E2B sandbox environment.
Method signature
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
port | number | Yes | The port number to get the host URL for |
Return value
Type | Description |
---|---|
string | The host URL that can be used to access the specified port in the sandbox |
Examples
Get Host for Web Server
Get Host for API Server
Get Host for Database Connection
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
Sandbox compatibility
Sandbox Type | Supported | Notes |
---|---|---|
E2B | ✅ Yes | Full support with automatic URL generation |
Daytona | ❌ No | Port forwarding not yet implemented |
FlyIO | ❌ No | Port forwarding not yet implemented |
Modal | ❌ No | Port 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