feat(sandbox): isolate worker/chat execution in Docker containers with lifecycle UI

- Add Docker sandbox manager, non-root sandbox image, compose isolation, and host firewall script (#217)
- Route Bash, custom commands/scripts, stdio MCP, chat sessions, MainAgent chat, and task-scoped reporter screenshots into sandbox containers with per-task browser concurrency gate
- Enforce proxy SSRF guard against loopback, metadata, internal services, and admin port
- Add dedicated /system/sandbox management page, /chat session sandbox control, and task detail sandbox popover with progressive stats loading
This commit is contained in:
ji ruo committed 2026-12-01 21:13:21 +08:00
1 parent 6bbeac588d
commit 9c43e694a3
44 files changed
+7086 -91

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
#!/bin/sh
# Close the host paths a sandbox container can use to reach ARTEX itself.
# The recording proxy already refuses loopback, metadata, postgres and the
# admin port. This script covers traffic that never enters the proxy:
# - packets from the sandbox bridge to the host's published :8787
# - packets routed from the sandbox bridge into the compose internal network
# (postgres, docker-socket-proxy, the ARTEX container)
# - packets toward the cloud metadata address
#
# Run on the Docker host after the networks exist. Safe to repeat.
set -eu
sandbox_net="${ARTEX_SANDBOX_NETWORK:-artex-sandbox}"
bridge_for() {
id=$(docker network inspect "$1" --format '{{.Id}}')
printf 'br-%.12s\n' "$id"
}
ensure() {
chain=$1
shift
if iptables -C "$chain" "$@" 2>/dev/null; then
return 0
fi
iptables -I "$chain" "$@"
}
if ! docker network inspect "$sandbox_net" >/dev/null 2>&1; then
echo "sandbox network $sandbox_net not found" >&2
exit 1
fi
sandbox_br=$(bridge_for "$sandbox_net")
ensure INPUT -i "$sandbox_br" -p tcp --dport 8787 -j REJECT
# Compose prefixes the internal network with the project name.
internal_net=$(docker network ls --format '{{.Name}}' | awk '/artex-internal$/ {print; exit}')
if [ -n "$internal_net" ]; then
internal_cidr=$(docker network inspect "$internal_net" --format '{{(index .IPAM.Config 0).Subnet}}')
if [ -n "$internal_cidr" ]; then
# Published :8788 is DNATed onto the ARTEX container, which lives in this
# subnet. Let only that port through, then refuse postgres, the Docker
# socket proxy, and the admin port.
ensure DOCKER-USER -i "$sandbox_br" -d "$internal_cidr" -j REJECT
ensure DOCKER-USER -i "$sandbox_br" -d "$internal_cidr" -p tcp --dport 8788 -j RETURN
fi
fi
ensure DOCKER-USER -i "$sandbox_br" -d 169.254.169.254/32 -j REJECT
echo "sandbox firewall applied on $sandbox_br"