-
Notifications
You must be signed in to change notification settings - Fork 248
feat: add Docker support #349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a37bc3f
0f28cfd
3208149
098cd31
7210dc8
0f490bd
74f06cf
7dc553f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| ARG DEBIAN_VERSION=13.2-slim | ||
| FROM debian:${DEBIAN_VERSION} | ||
|
|
||
| ARG DEBIAN_FRONTEND=noninteractive | ||
| ARG MICROSANDBOX_VERSION=latest | ||
| ARG TARGETARCH | ||
|
|
||
| RUN apt update && \ | ||
| apt install -y --no-install-recommends \ | ||
| ca-certificates \ | ||
| curl && \ | ||
| apt clean && \ | ||
| rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Download and install microsandbox binary | ||
| RUN VERSION ="${MICROSANDBOX_VERSION:-}" \ | ||
| curl -fsSL https://raw.githubusercontent.com/zerocore-ai/microsandbox/refs/heads/main/scripts/install_microsandbox.sh | sh | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would recommend to copy the source code and compile it in the docker build process. This makes releasing a lot easier. |
||
|
|
||
| # Set up environment variables | ||
| ENV PATH="/root/.local/bin:/usr/local/bin:${PATH:-/bin:/usr/bin}" | ||
| ENV LD_LIBRARY_PATH="/root/.local/lib:/usr/local/lib:${LD_LIBRARY_PATH:-/usr/local/lib:/usr/lib}" | ||
| ENV HOME="/root" | ||
|
|
||
| WORKDIR /root | ||
|
|
||
| ARG MICROSANDBOX_AUTO_PULL_IMAGES=true | ||
| RUN if [ "${MICROSANDBOX_AUTO_PULL_IMAGES}" = "true" ]; then \ | ||
| msb pull microsandbox/python && \ | ||
| msb pull microsandbox/node; \ | ||
| fi | ||
|
|
||
| VOLUME [ "/root/.microsandbox/namespaces" ] | ||
|
|
||
| # Default to microsandbox CLI | ||
| ENTRYPOINT ["msb"] | ||
| CMD ["server", "start", "--host", "0.0.0.0", "--port", "5555"] | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,69 @@ | ||||||||
| # Docker Setup for Microsandbox | ||||||||
|
|
||||||||
| This directory contains Docker and Docker Compose configurations for running Microsandbox in a containerized environment. | ||||||||
|
|
||||||||
| ## Quick Start | ||||||||
|
|
||||||||
| ```bash | ||||||||
| docker compose -f docker/docker-compose.yaml up -d | ||||||||
| ``` | ||||||||
|
|
||||||||
| ## Configuration | ||||||||
|
|
||||||||
| You can customize the deployment using environment variables: | ||||||||
|
|
||||||||
| - `MICROSANDBOX_VERSION`: Version tag (default: `latest`) | ||||||||
| - `MICROSANDBOX_PORT`: Port to expose (default: `5555`) | ||||||||
| - `MICROSANDBOX_DEV_MODE`: Enable development mode without API key (default: `true`) | ||||||||
| - `MICROSANDBOX_CPU_LIMIT`: CPU limit (default: `4`) | ||||||||
| - `MICROSANDBOX_MEMORY_LIMIT`: Memory limit (default: `8G`) | ||||||||
| - `TZ`: Timezone (default: `UTC`) | ||||||||
|
|
||||||||
| ## Security Considerations | ||||||||
|
|
||||||||
| ### Privileged Container Mode | ||||||||
|
|
||||||||
| **Important**: This Docker configuration runs the container in **privileged mode** with **unconfined AppArmor and seccomp profiles**. This significantly reduces container security by disabling key isolation mechanisms. | ||||||||
|
|
||||||||
| ### Why These Security Exceptions Are Required | ||||||||
|
|
||||||||
| Microsandbox requires these elevated privileges for the following reasons: | ||||||||
|
|
||||||||
| 1. **KVM Device Access** (`/dev/kvm`): Enables hardware-accelerated virtualization for running secure VMs inside the container | ||||||||
| 2. **TUN/TAP Network Devices** (`/dev/net/tun`): Allows creation of network tunnels for VM networking | ||||||||
| 3. **Privileged Mode**: Required for proper device access and VM functionality | ||||||||
|
|
||||||||
| ### Security Implications | ||||||||
|
|
||||||||
| While the container runs with reduced security isolation, the **purpose of Microsandbox is to provide secure, isolated VM environments** for executing untrusted code. The security model is: | ||||||||
|
|
||||||||
| - **Container layer**: Reduced isolation (privileged mode) | ||||||||
| - **VM layer**: Strong isolation through hardware virtualization (KVM) | ||||||||
|
|
||||||||
| The VM-based isolation provides the actual security boundary for untrusted code execution. | ||||||||
|
|
||||||||
| ### Recommendations | ||||||||
|
|
||||||||
| - **Do not run this container in untrusted environments** without additional security measures | ||||||||
| - **Restrict network access** to the Microsandbox API endpoint | ||||||||
| - **Use API keys in production** by setting `MICROSANDBOX_DEV_MODE=false` | ||||||||
| - **Monitor container resource usage** to prevent DoS attacks | ||||||||
| - **Keep the Microsandbox version up to date** for security patches | ||||||||
|
|
||||||||
| ## Volumes | ||||||||
|
|
||||||||
| - `microsandbox_config`: Stores namespace configurations in `/root/.microsandbox/namespaces` | ||||||||
| - `microsandbox_workspace`: Workspace directory for file operations | ||||||||
|
|
||||||||
| ## Building the Image | ||||||||
|
|
||||||||
| ```bash | ||||||||
| cd docker | ||||||||
| docker-compose build | ||||||||
|
Comment on lines
+61
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
More consistent with the other examples |
||||||||
| ``` | ||||||||
|
|
||||||||
| Or build manually: | ||||||||
|
|
||||||||
| ```bash | ||||||||
| docker build -t ghcr.io/zerocore-ai/microsandbox:latest -f docker/Dockerfile . | ||||||||
| ``` | ||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,48 @@ | ||||||||||||||||||||||||||||||||||||||
| services: | ||||||||||||||||||||||||||||||||||||||
Sun-ZhenXing marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
| microsandbox: | ||||||||||||||||||||||||||||||||||||||
| image: ghcr.io/zerocore-ai/microsandbox:${MICROSANDBOX_VERSION:-latest} | ||||||||||||||||||||||||||||||||||||||
| build: | ||||||||||||||||||||||||||||||||||||||
| context: . | ||||||||||||||||||||||||||||||||||||||
Sun-ZhenXing marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
| dockerfile: Dockerfile | ||||||||||||||||||||||||||||||||||||||
| args: | ||||||||||||||||||||||||||||||||||||||
| - DEBIAN_VERSION=${DEBIAN_VERSION:-13.2-slim} | ||||||||||||||||||||||||||||||||||||||
| - MICROSANDBOX_VERSION=${MICROSANDBOX_VERSION:-latest} | ||||||||||||||||||||||||||||||||||||||
| - MICROSANDBOX_AUTO_PULL_IMAGES=${MICROSANDBOX_AUTO_PULL_IMAGES:-true} | ||||||||||||||||||||||||||||||||||||||
| restart: unless-stopped | ||||||||||||||||||||||||||||||||||||||
| ports: | ||||||||||||||||||||||||||||||||||||||
| - ${MICROSANDBOX_PORT_OVERRIDE:-5555}:${MICROSANDBOX_PORT:-5555} | ||||||||||||||||||||||||||||||||||||||
| privileged: true | ||||||||||||||||||||||||||||||||||||||
| security_opt: | ||||||||||||||||||||||||||||||||||||||
| - apparmor=unconfined | ||||||||||||||||||||||||||||||||||||||
Sun-ZhenXing marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
| - seccomp=unconfined | ||||||||||||||||||||||||||||||||||||||
Sun-ZhenXing marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
| environment: | ||||||||||||||||||||||||||||||||||||||
| - TZ=${TZ:-UTC} | ||||||||||||||||||||||||||||||||||||||
| - MICROSANDBOX_HOME=/root/.microsandbox | ||||||||||||||||||||||||||||||||||||||
| volumes: | ||||||||||||||||||||||||||||||||||||||
| - microsandbox_config:/root/.microsandbox/namespaces | ||||||||||||||||||||||||||||||||||||||
Sun-ZhenXing marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
| - microsandbox_workspace:/workspace | ||||||||||||||||||||||||||||||||||||||
| devices: | ||||||||||||||||||||||||||||||||||||||
Sun-ZhenXing marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
| - /dev/kvm:/dev/kvm | ||||||||||||||||||||||||||||||||||||||
| command: | ||||||||||||||||||||||||||||||||||||||
| - /bin/sh | ||||||||||||||||||||||||||||||||||||||
| - -c | ||||||||||||||||||||||||||||||||||||||
| - > | ||||||||||||||||||||||||||||||||||||||
| if [ "${MICROSANDBOX_DEV_MODE:-true}" = "true" ]; then | ||||||||||||||||||||||||||||||||||||||
| DEV_FLAG="--dev"; | ||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||
| DEV_FLAG=""; | ||||||||||||||||||||||||||||||||||||||
| fi; | ||||||||||||||||||||||||||||||||||||||
| exec server start --host 0.0.0.0 --port ${MICROSANDBOX_PORT:-5555} ${DEV_FLAG}; | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+26
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Main problem is that the |
||||||||||||||||||||||||||||||||||||||
| working_dir: /root | ||||||||||||||||||||||||||||||||||||||
| deploy: | ||||||||||||||||||||||||||||||||||||||
| resources: | ||||||||||||||||||||||||||||||||||||||
| limits: | ||||||||||||||||||||||||||||||||||||||
| cpus: ${MICROSANDBOX_CPU_LIMIT:-4} | ||||||||||||||||||||||||||||||||||||||
| memory: ${MICROSANDBOX_MEMORY_LIMIT:-8G} | ||||||||||||||||||||||||||||||||||||||
| reservations: | ||||||||||||||||||||||||||||||||||||||
| cpus: ${MICROSANDBOX_CPU_RESERVATION:-1} | ||||||||||||||||||||||||||||||||||||||
| memory: ${MICROSANDBOX_MEMORY_RESERVATION:-2G} | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| volumes: | ||||||||||||||||||||||||||||||||||||||
| microsandbox_config: | ||||||||||||||||||||||||||||||||||||||
| microsandbox_workspace: | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.