Use Hopx with Docker, CI/CD pipelines, and other development tools
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.
Use Hopx SDK in Docker containers for containerized applications and microservices.
Python
JavaScript/TypeScript
Copy
FROM python:3.11-slim# Install Hopx SDKRUN pip install hopx-ai# Your application codeCOPY . /appWORKDIR /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:
Copy
from hopx_ai import Sandbox# Create and use sandboxwith 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.
Always clean up sandboxes after use, especially in CI/CD:
Copy
# Pythonwith Sandbox.create(template="code-interpreter") as sandbox: # Your code here pass # Auto-cleanup on exit# Or manuallysandbox = Sandbox.create(template="code-interpreter")try: # Your code here passfinally: sandbox.kill()
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
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