From 98681e54a21eeaf92af6120a5cf0b3e94c6f98d4 Mon Sep 17 00:00:00 2001 From: Yash Shah Date: Fri, 18 Sep 2026 19:23:55 +0530 Subject: [PATCH] feat(docker): runtime-docker image and compose.docker-sandbox overlay Context: - Docker sandbox backend needed docker-cli in the image and a same-path TMPDIR bind-mount for nested docker run -v on Docker Desktop. - Without a compose path, agentforge and ops users stayed on subprocess. Test Plan: - AGENTBOX_HOST_TMP=$PWD/.agentbox-work docker compose -f compose.yaml \ -f compose.docker-sandbox.yaml up --build -d agentbox - curl /health shows backend=docker; POST /v1/run with network_isolated=true Additional Notes: - Default compose remains subprocess for simple CI/unit use. --- .gitignore | 1 + README.md | 14 +++++++++++--- compose.docker-sandbox.yaml | 14 ++++++++++++++ docker/Dockerfile | 7 +++++++ 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 compose.docker-sandbox.yaml diff --git a/.gitignore b/.gitignore index aa21101..bf896e1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ __pycache__/ .venv/ .pytest_cache/ dist/ +.agentbox-work/ diff --git a/README.md b/README.md index 7184864..32beac6 100644 --- a/README.md +++ b/README.md @@ -125,11 +125,19 @@ client.close() ## Docker ```bash -docker compose up agentbox # start API on :8080 -docker compose run --rm test # run unit tests +docker compose up agentbox # start API on :8080 (subprocess backend) +docker compose run --rm test # unit tests ``` -Note: using `AGENTBOX_SANDBOX_BACKEND=docker` from inside a container needs Docker socket access (DinD / mounted socket). Prefer running the API on the host with the Docker backend, or keep the compose service on `subprocess`. +### Compose + Docker sandbox backend + +```bash +export AGENTBOX_HOST_TMP="$(pwd)/.agentbox-work" +mkdir -p "$AGENTBOX_HOST_TMP" +docker compose -f compose.yaml -f compose.docker-sandbox.yaml up --build agentbox +``` + +Uses image target `runtime-docker` (`docker-cli` + `AGENTBOX_SANDBOX_BACKEND=docker`), mounts the Docker socket, and bind-mounts `AGENTBOX_HOST_TMP` at the **same absolute path** so nested `docker run -v` works on Docker Desktop. ## Configuration diff --git a/compose.docker-sandbox.yaml b/compose.docker-sandbox.yaml new file mode 100644 index 0000000..aa181db --- /dev/null +++ b/compose.docker-sandbox.yaml @@ -0,0 +1,14 @@ +# Use: mkdir -p "$AGENTBOX_HOST_TMP" && \ +# AGENTBOX_HOST_TMP="$(pwd)/.agentbox-work" \ +# docker compose -f compose.yaml -f compose.docker-sandbox.yaml up --build agentbox +services: + agentbox: + build: + target: runtime-docker + environment: + AGENTBOX_SANDBOX_BACKEND: docker + TMPDIR: ${AGENTBOX_HOST_TMP:?Set AGENTBOX_HOST_TMP to an absolute host path} + AGENTBOX_SNAPSHOT_DIR: ${AGENTBOX_HOST_TMP}/snapshots + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - ${AGENTBOX_HOST_TMP}:${AGENTBOX_HOST_TMP} diff --git a/docker/Dockerfile b/docker/Dockerfile index 08fed8f..526b3b1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -17,3 +17,10 @@ RUN pip install --no-cache-dir . EXPOSE 8080 HEALTHCHECK CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health')" CMD ["agentbox", "serve", "--host", "0.0.0.0", "--port", "8080"] + +# Docker sandbox backend: needs docker CLI + mounted docker.sock (see compose profile). +# Nested `docker run -v` requires TMPDIR bind-mounted at the same absolute host path. +FROM runtime AS runtime-docker +RUN apt-get update && apt-get install -y --no-install-recommends docker-cli \ + && rm -rf /var/lib/apt/lists/* +ENV AGENTBOX_SANDBOX_BACKEND=docker