Leon4gr45 commited on
Commit
3e7bb00
·
verified ·
1 Parent(s): 2bd7bb8

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. Dockerfile +31 -0
  2. README.md +42 -1
  3. config.template.yaml +41 -0
  4. nginx.conf +38 -0
  5. start.sh +20 -0
Dockerfile ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.12-slim
2
+
3
+ ENV PLAYWRIGHT_BROWSERS_PATH=/opt/pw-browsers
4
+ WORKDIR /app
5
+
6
+ RUN apt-get update && apt-get install -y --no-install-recommends \
7
+ curl gettext-base nginx \
8
+ && rm -rf /var/lib/apt/lists/*
9
+
10
+ RUN pip install --no-cache-dir --upgrade pip \
11
+ && pip install --no-cache-dir "magentic_ui>=0.2.0"
12
+
13
+ # Chromium + its OS-level deps, for the (unsandboxed) local browser path.
14
+ RUN playwright install --with-deps chromium
15
+
16
+ # Run as non-root: Chromium refuses to launch as root without --no-sandbox,
17
+ # which magentic-ui's local browser path doesn't pass.
18
+ RUN useradd -m -u 1000 appuser \
19
+ && chown -R appuser:appuser /opt/pw-browsers /app /var/lib/nginx /var/log/nginx
20
+
21
+ COPY --chown=appuser:appuser config.template.yaml /app/config.template.yaml
22
+ COPY --chown=appuser:appuser nginx.conf /app/nginx.conf
23
+ COPY --chown=appuser:appuser start.sh /app/start.sh
24
+ RUN chmod +x /app/start.sh
25
+
26
+ USER appuser
27
+ ENV HOME=/home/appuser
28
+
29
+ EXPOSE 7860
30
+
31
+ CMD ["/app/start.sh"]
README.md CHANGED
@@ -4,7 +4,48 @@ emoji: 🌍
4
  colorFrom: purple
5
  colorTo: pink
6
  sdk: docker
 
7
  pinned: false
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  colorFrom: purple
5
  colorTo: pink
6
  sdk: docker
7
+ app_port: 7860
8
  pinned: false
9
  ---
10
 
11
+ Self-hosted [Magentic-UI / MagenticLite](https://github.com/microsoft/magentic-ui) —
12
+ a human-centered multi-agent web/browser automation assistant, pointed at
13
+ any OpenAI-compatible endpoint. Chromium browser, no stored credentials —
14
+ the known-working configuration.
15
+
16
+ ## Required Space secrets
17
+
18
+ | Secret | Description |
19
+ |---|---|
20
+ | `OPENAI_BASE_URL` | Base URL of an OpenAI-compatible `/v1/chat/completions` API (vLLM, OpenRouter, your own gateway, etc.). |
21
+ | `OPENAI_MODEL` | Model id used for both agent roles, unless overridden below. |
22
+ | `OPENAI_API_KEY` | Bearer token. Passed straight through as an env var to the process — never written into the generated config file. |
23
+
24
+ ## Optional secrets
25
+
26
+ | Secret | Description |
27
+ |---|---|
28
+ | `ORCHESTRATOR_MODEL` | Model for the orchestrator role (plans, produces the final answer). Defaults to `OPENAI_MODEL`. Text-only is fine. |
29
+ | `WEBSURFER_MODEL` | Model for the web-surfer role (drives the browser). Defaults to `OPENAI_MODEL`. **Needs vision support** — the browser-use agent reads screenshots. If your model can't do vision, point this at one that can, or set `agent_mode: omniagent_only` in `config.template.yaml` to disable browsing entirely. |
30
+
31
+ ## Architecture notes
32
+
33
+ - **No Quicksand VM sandbox.** Magentic-UI normally isolates the browser/code-execution agent inside a lightweight QEMU VM ([Quicksand](https://microsoft.github.io/quicksand/)), which needs KVM/nested virtualization — not available on standard HF Spaces hardware. This deployment sets `sandbox: type: "null"` instead (note: must be the literal *string* `"null"` — Magentic-UI's config is a Pydantic `Literal["null"]`, and YAML's unquoted `null`/`None` doesn't match it, silently falling back to Quicksand and crashing since `quicksand-cua` isn't installed in this image). With the sandbox disabled, the agent's browser and code execution run **directly in this container**, unisolated. This is an explicit, documented Magentic-UI mode ("dev/testing only" per their docs) — reasonable for a single-tenant personal Space, but keep in mind a compromised/prompt-injected page could interact with the container directly.
34
+ - **No noVNC, but screenshots work.** The live-browser-view requirement is partly met: Magentic-UI has a generic `browser_screenshot` message type that streams periodic screenshots to the chat UI regardless of sandbox type, so you can see what the agent's browser is doing. What you *don't* get without Quicksand is the smoother continuous noVNC video feed — that's wired specifically to the Quicksand VM's own VNC server, which doesn't exist in the null-sandbox path.
35
+ - **Internal nginx reverse proxy for the Host-header check.** Magentic-UI hardcodes a Host-header allowlist of only `localhost`/`127.0.0.1` (a DNS-rebinding defense) with no config override — so it flatly rejects requests proxied in under this Space's public hostname (`Bad Host header`, HTTP 400). `start.sh` runs magentic-ui bound to `127.0.0.1:8081` (not exposed) behind an nginx instance on `0.0.0.0:7860` (the actual exposed port) that rewrites the `Host` header to `localhost` before forwarding, including WebSocket upgrade support for the real-time chat stream.
36
+ - **Runs as a non-root user.** Chromium (launched by Playwright, for the browser-use agent) refuses to start as root without `--no-sandbox`, which Magentic-UI's local browser path doesn't pass. The Dockerfile creates and runs as `appuser` to sidestep this instead of patching Chromium flags.
37
+ - Both model roles are configured as generic `OpenAIChatCompletionClient`s — any server speaking the OpenAI chat completions API works.
38
+
39
+ ## History
40
+
41
+ This Space is a fresh deployment of the same configuration that was
42
+ previously proven working on `Leon4gr45/webagent` before that Space got
43
+ auto-paused by Hugging Face's abuse-detector (a literal process-cmdline
44
+ match against a since-abandoned Camoufox-based browser swap — unrelated
45
+ to anything in this Dockerfile). A separate attempt to add a
46
+ credential-vault feature (stored login/signup secrets so the agent could
47
+ log in to sites) also got auto-paused, before it even built, by a
48
+ different (static content-scan) abuse rule — that feature was dropped
49
+ rather than deployed here. This Space intentionally carries **no stored
50
+ credentials** and no browser-engine swap: just plain Playwright-Chromium,
51
+ the configuration already confirmed to run cleanly end-to-end.
config.template.yaml ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Rendered to /app/config.yaml at container startup by start.sh (envsubst).
2
+ # api_key is deliberately omitted here - magentic-ui's _ai_client.py falls
3
+ # back to the OPENAI_API_KEY env var, so the secret never touches disk.
4
+
5
+ model_client_configs:
6
+ orchestrator:
7
+ provider: OpenAIChatCompletionClient
8
+ config:
9
+ model: ${ORCHESTRATOR_MODEL}
10
+ base_url: ${OPENAI_BASE_URL}
11
+ max_retries: 5
12
+ model_info:
13
+ vision: false
14
+ function_calling: false
15
+ json_output: true
16
+ family: unknown
17
+ structured_output: false
18
+ multiple_system_messages: false
19
+
20
+ web_surfer:
21
+ provider: OpenAIChatCompletionClient
22
+ config:
23
+ model: ${WEBSURFER_MODEL}
24
+ base_url: ${OPENAI_BASE_URL}
25
+ max_retries: 5
26
+ model_info:
27
+ vision: true
28
+ function_calling: false
29
+ json_output: true
30
+ family: unknown
31
+ structured_output: false
32
+ multiple_system_messages: false
33
+
34
+ # No Quicksand VM (needs KVM/nested virtualization, not available on
35
+ # standard HF Spaces hardware) - the agent's browser/code execution runs
36
+ # directly in this container instead. Less isolated; fine for a
37
+ # single-tenant personal Space, not recommended for multi-tenant use.
38
+ sandbox:
39
+ type: "null"
40
+
41
+ agent_mode: all
nginx.conf ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ worker_processes 1;
2
+ pid /tmp/nginx.pid;
3
+ error_log /tmp/nginx_error.log;
4
+
5
+ events {
6
+ worker_connections 1024;
7
+ }
8
+
9
+ http {
10
+ access_log /tmp/nginx_access.log;
11
+ client_body_temp_path /tmp/nginx_client_temp;
12
+ proxy_temp_path /tmp/nginx_proxy_temp;
13
+ client_max_body_size 50M;
14
+
15
+ map $http_upgrade $connection_upgrade {
16
+ default upgrade;
17
+ '' close;
18
+ }
19
+
20
+ server {
21
+ listen 7860;
22
+
23
+ location / {
24
+ # magentic-ui hardcodes a Host-header allowlist of only
25
+ # localhost/127.0.0.1 (DNS-rebinding defense) with no override,
26
+ # which rejects HF's proxy Host header outright. Rewrite it here
27
+ # instead of patching magentic-ui's source.
28
+ proxy_pass http://127.0.0.1:8081;
29
+ proxy_set_header Host localhost;
30
+
31
+ proxy_http_version 1.1;
32
+ proxy_set_header Upgrade $http_upgrade;
33
+ proxy_set_header Connection $connection_upgrade;
34
+ proxy_read_timeout 3600s;
35
+ proxy_send_timeout 3600s;
36
+ }
37
+ }
38
+ }
start.sh ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ set -e
3
+
4
+ export ORCHESTRATOR_MODEL="${ORCHESTRATOR_MODEL:-$OPENAI_MODEL}"
5
+ export WEBSURFER_MODEL="${WEBSURFER_MODEL:-$OPENAI_MODEL}"
6
+
7
+ if [ -z "$OPENAI_BASE_URL" ]; then
8
+ echo "ERROR: OPENAI_BASE_URL is not set. Configure it as a Space secret." >&2
9
+ exit 1
10
+ fi
11
+
12
+ envsubst < /app/config.template.yaml > /app/config.yaml
13
+
14
+ # nginx (0.0.0.0:7860, HF's exposed port) rewrites the Host header to
15
+ # localhost before forwarding to magentic-ui (127.0.0.1:8081, internal
16
+ # only) - magentic-ui hardcodes a localhost/127.0.0.1-only Host allowlist
17
+ # with no override, which would otherwise reject HF's proxy Host header.
18
+ nginx -c /app/nginx.conf
19
+
20
+ exec magentic-ui --host 127.0.0.1 --port 8081 --appdir /home/appuser/.magentic_ui --config /app/config.yaml