Skip to content

Enterprise agent platform for building, deploying, and operating AI teammates.

3.5 KB
Raw Blame
services:
  backend:
    environment:
      - SANDBOX_ENABLED=true
      - SANDBOX_IMPLEMENTATION=docker
      - DOCKER_HOST=unix:///var/run/docker.sock
      - SANDBOX_IMAGE=xprobe/xagent-sandbox:0.8.6
      - SANDBOX_CPUS=1
      - SANDBOX_MEMORY=512
      - XAGENT_SANDBOX_HOST_PROJECT_ROOT=${XAGENT_SANDBOX_HOST_PROJECT_ROOT:-${PWD}}
      - XAGENT_SANDBOX_HOST_STORAGE_ROOT=${XAGENT_HOST_STORAGE_ROOT:-/root/.xagent}
      - XAGENT_SANDBOX_NAMESPACE=${COMPOSE_PROJECT_NAME:?set COMPOSE_PROJECT_NAME to a stable unique value}
      - XAGENT_SANDBOX_NETWORK=${XAGENT_SANDBOX_NETWORK:?set XAGENT_SANDBOX_NETWORK to the dedicated sandbox bridge}
      - XAGENT_SANDBOX_WORKER_ID=backend
    volumes:
      - type: bind
        source: ${XAGENT_HOST_STORAGE_ROOT:-/root/.xagent}
        target: /root/.xagent
      - type: bind
        source: /var/run/docker.sock
        target: /var/run/docker.sock
        bind:
          create_host_path: false

  nginx:
    # nginx drops privileges and calls initgroups(), which discards Docker's
    # supplementary group_add entries. Resolve/create gid 1010 in the image's
    # group database and make it the worker's primary group so X-Accel can
    # traverse sandbox-managed 2750 directories. Keep this override scoped to
    # the Docker sandbox deployment, which is the only mode that needs it.
    command:
      - /bin/sh
      - -c
      - |
        set -eu
        group_file="$${XAGENT_NGINX_GROUP_FILE:-/etc/group}"
        nginx_conf="$${XAGENT_NGINX_CONF:-/etc/nginx/nginx.conf}"
        group_name="$$(awk -F: '$$3 == 1010 { print $$1; exit }' "$${group_file}")"
        if [ -z "$${group_name}" ]; then
          group_name=xagent_sandbox
          printf '%s:x:1010:\n' "$${group_name}" >> "$${group_file}"
        fi
        tmp_conf="$${nginx_conf}.xagent.tmp"
        if ! awk -v group_name="$${group_name}" '
          BEGIN { replaced = 0 }
          /^user[[:space:]]+[^;]+;/ {
            print "user nginx " group_name ";"
            replaced = 1
            next
          }
          { print }
          END { if (!replaced) exit 1 }
        ' "$${nginx_conf}" > "$${tmp_conf}"; then
          rm -f "$${tmp_conf}"
          echo "failed to find nginx user directive" >&2
          exit 1
        fi
        cat "$${tmp_conf}" > "$${nginx_conf}"
        rm -f "$${tmp_conf}"
        grep -q "^user nginx $${group_name};" "$${nginx_conf}" || {
          echo "failed to configure nginx primary group $${group_name}" >&2
          exit 1
        }
        exec nginx -g 'daemon off;'
    volumes:
      - type: bind
        source: ${XAGENT_HOST_STORAGE_ROOT:-/root/.xagent}
        target: /root/.xagent
        read_only: true

  worker:
    environment:
      - XAGENT_SANDBOX_NAMESPACE=${COMPOSE_PROJECT_NAME:?set COMPOSE_PROJECT_NAME to a stable unique value}
      - XAGENT_SANDBOX_NETWORK=${XAGENT_SANDBOX_NETWORK:?set XAGENT_SANDBOX_NETWORK to the dedicated sandbox bridge}
      - XAGENT_SANDBOX_WORKER_ID=celery-worker
    volumes:
      - type: bind
        source: ${XAGENT_HOST_STORAGE_ROOT:-/root/.xagent}
        target: /root/.xagent

  scheduler:
    environment:
      - XAGENT_SANDBOX_NAMESPACE=${COMPOSE_PROJECT_NAME:?set COMPOSE_PROJECT_NAME to a stable unique value}
      - XAGENT_SANDBOX_NETWORK=${XAGENT_SANDBOX_NETWORK:?set XAGENT_SANDBOX_NETWORK to the dedicated sandbox bridge}
      - XAGENT_SANDBOX_WORKER_ID=scheduler
    volumes:
      - type: bind
        source: ${XAGENT_HOST_STORAGE_ROOT:-/root/.xagent}
        target: /root/.xagent