Skip to main content
Learn how to troubleshoot network and connection issues with Hopx Sandboxes.

Network Connectivity Issues

Check Network Connection

Verify network connectivity:
  • Python
  • JavaScript/TypeScript
from hopx_ai import Sandbox
from hopx_ai.errors import NetworkError

def test_connection():
    """Test network connection"""
    try:
        sandbox = Sandbox.create(template="code-interpreter")
        print("✅ Connection successful")
        return True
    except NetworkError as e:
        print(f"❌ Network error: {e.message}")
        return False
    except Exception as e:
        print(f"❌ Error: {e}")
        return False

# Test connection
if test_connection():
    print("Network is working")
else:
    print("Check your network connection")

Timeout Issues

Handle timeout issues:
  • Python
  • JavaScript/TypeScript
from hopx_ai import Sandbox
from hopx_ai.errors import TimeoutError

def execute_with_timeout_handling(code: str, timeout: int = 30):
    """Execute code with timeout handling"""
    try:
        with Sandbox.create(template="code-interpreter") as sandbox:
            result = sandbox.run_code(code, timeout=timeout)
            return result
    except TimeoutError:
        print(f"❌ Execution timed out after {timeout} seconds")
        print("💡 Try increasing timeout or optimizing code")
        return None

# Example
result = execute_with_timeout_handling("""
import time
time.sleep(60)  # Long operation
""", timeout=30)

Region Selection

Choose the closest region for better performance:
  • Python
  • JavaScript/TypeScript
from hopx_ai import Sandbox

# ✅ Good: Use closest region
sandbox = Sandbox.create(
    template="code-interpreter",
    region="us-east-1"  # Choose closest region
)

Retry Logic for Network Issues

Implement retry logic for transient network issues:
  • Python
  • JavaScript/TypeScript
from hopx_ai import Sandbox
from hopx_ai.errors import NetworkError, TimeoutError
import time

def execute_with_retry(code: str, max_retries: int = 3):
    """Execute with retry logic for network issues"""
    for attempt in range(max_retries):
        try:
            with Sandbox.create(template="code-interpreter") as sandbox:
                return sandbox.run_code(code)
        except (NetworkError, TimeoutError) as e:
            if attempt < max_retries - 1:
                wait_time = 2 ** attempt  # Exponential backoff
                print(f"Retry {attempt + 1}/{max_retries} after {wait_time}s...")
                time.sleep(wait_time)
                continue
            raise
    return None

# Example
result = execute_with_retry("print('Hello')")

Common Connection Issues

Symptoms: Requests timeout before completingSolutions:
  • Check network connectivity
  • Increase timeout values
  • Use closer regions
  • Check firewall settings
Symptoms: Network-related errorsSolutions:
  • Verify internet connection
  • Check firewall/proxy settings
  • Try different network
  • Implement retry logic
Symptoms: Slow response timesSolutions:
  • Use closer regions
  • Check network bandwidth
  • Optimize request size
  • Use connection pooling
Symptoms: Occasional connection failuresSolutions:
  • Implement retry logic
  • Use exponential backoff
  • Check network stability
  • Monitor connection quality

Troubleshooting Checklist

  • Internet connection is working
  • Firewall allows outbound connections
  • Proxy settings are correct
  • DNS resolution is working
  • API key is valid
  • Region is accessible
  • Timeout values are appropriate
  • Retry logic is implemented
  • Using closest region
  • Network latency is acceptable
  • Bandwidth is sufficient
  • Connection pooling is used

Next Steps