Skip to main content
Integrate Hopx into your development workflow with Docker and CI/CD pipelines. Run tests in isolated sandboxes, build containerized applications, and automate your deployment workflows.
Hopx sandboxes provide isolated environments perfect for CI/CD pipelines, testing untrusted code, and building containerized applications. Each sandbox is ephemeral and automatically cleaned up after use.

Why Use Hopx in Development Tools?

  • Isolated Testing - Run tests in clean, isolated environments
  • Security - Execute untrusted code safely without affecting your infrastructure
  • Consistency - Same environment across local, CI/CD, and production
  • Fast Startup - Sandboxes start in ~0.1s, perfect for CI/CD pipelines
  • Multi-Language - Support for Python, JavaScript, Bash, and Go

Docker Integration

Use Hopx SDK in Docker containers for containerized applications and microservices.
  • Python
  • JavaScript/TypeScript
FROM python:3.11-slim

# Install Hopx SDK
RUN pip install hopx-ai

# Your application code
COPY . /app
WORKDIR /app

# Set API key at runtime (use Docker secrets or environment variables)
ENV HOPX_API_KEY=${HOPX_API_KEY}

CMD ["python", "app.py"]
Example usage in your Python application:
from hopx_ai import Sandbox

# Create and use sandbox
with Sandbox.create(template="code-interpreter") as sandbox:
    result = sandbox.run_code("print('Hello from Docker!')")
    print(result.stdout)
Never hardcode API keys in Dockerfiles. Always use environment variables, Docker secrets, or secret management services. Pass the API key at runtime using -e HOPX_API_KEY=your-key or Docker Compose environment files.

Multi-Stage Build Example

For production Docker images, use multi-stage builds to reduce image size:
# Build stage
FROM python:3.11-slim as builder
RUN pip install --user hopx-ai

# Runtime stage
FROM python:3.11-slim
COPY --from=builder /root/.local /root/.local
COPY . /app
WORKDIR /app
ENV PATH=/root/.local/bin:$PATH
ENV HOPX_API_KEY=${HOPX_API_KEY}
CMD ["python", "app.py"]

CI/CD Integration

Use Hopx in your CI/CD pipelines to run tests, execute code, and validate deployments in isolated environments.

GitHub Actions

  • Python
  • JavaScript/TypeScript
name: Test with Hopx
on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      
      - name: Install dependencies
        run: pip install hopx-ai pytest
      
      - name: Run tests
        env:
          HOPX_API_KEY: ${{ secrets.HOPX_API_KEY }}
        run: pytest tests/
Example test file (tests/test_sandbox.py):
import pytest
from hopx_ai import Sandbox

def test_code_execution():
    with Sandbox.create(template="code-interpreter") as sandbox:
        result = sandbox.run_code("print('Test passed!')")
        assert result.success
        assert "Test passed!" in result.stdout

GitLab CI

  • Python
  • JavaScript/TypeScript
test:
  image: python:3.11-slim
  before_script:
    - pip install hopx-ai pytest
  script:
    - pytest tests/
  variables:
    HOPX_API_KEY: $HOPX_API_KEY

CircleCI

  • Python
  • JavaScript/TypeScript
version: 2.1
jobs:
  test:
    docker:
      - image: cimg/python:3.11
    steps:
      - checkout
      - run:
          name: Install dependencies
          command: pip install hopx-ai pytest
      - run:
          name: Run tests
          command: pytest tests/
          environment:
            HOPX_API_KEY: ${HOPX_API_KEY}

Best Practices

Always use environment variables or secret management services for API keys in CI/CD:
# GitHub Actions
env:
  HOPX_API_KEY: ${{ secrets.HOPX_API_KEY }}

# GitLab CI
variables:
  HOPX_API_KEY: $HOPX_API_KEY

# CircleCI
environment:
  HOPX_API_KEY: ${HOPX_API_KEY}
Never commit API keys to version control.
Always clean up sandboxes after use, especially in CI/CD:
# Python
with Sandbox.create(template="code-interpreter") as sandbox:
    # Your code here
    pass  # Auto-cleanup on exit

# Or manually
sandbox = Sandbox.create(template="code-interpreter")
try:
    # Your code here
    pass
finally:
    sandbox.kill()
// JavaScript
const sandbox = await Sandbox.create({ template: 'code-interpreter' });
try {
  // Your code here
} finally {
  await sandbox.kill();
}
Set appropriate timeouts for CI/CD environments:
# Quick tests
result = sandbox.run_code(code, timeout=30)

# Longer operations
result = sandbox.run_code(code, timeout=300)  # 5 minutes max
Run tests in parallel for faster CI/CD pipelines:
import asyncio
from hopx_ai import Sandbox

async def run_test(test_code):
    async with Sandbox.create_async(template="code-interpreter") as sandbox:
        return await sandbox.run_code_async(test_code)

# Run multiple tests in parallel
async def main():
    tests = ["test1", "test2", "test3"]
    results = await asyncio.gather(*[run_test(code) for code in tests])
    return results

Use Cases

Automated Testing

Run integration tests in isolated sandboxes:
def test_data_processing():
    with Sandbox.create(template="code-interpreter") as sandbox:
        # Upload test data
        sandbox.files.write("/workspace/data.csv", test_data)
        
        # Run processing
        result = sandbox.run_code("""
            import pandas as pd
            df = pd.read_csv('/workspace/data.csv')
            print(df.describe())
        """)
        
        assert result.success

Code Validation

Validate user-submitted code safely:
def validate_code(user_code: str) -> bool:
    with Sandbox.create(template="code-interpreter") as sandbox:
        result = sandbox.run_code(user_code, timeout=10)
        return result.success and result.exit_code == 0

Build Verification

Test builds in clean environments:
def test_build():
    with Sandbox.create(template="code-interpreter") as sandbox:
        # Install dependencies
        sandbox.commands.run("pip install -r requirements.txt")
        
        # Run build
        result = sandbox.commands.run("python setup.py build")
        assert result.exit_code == 0

Next Steps