Repository navigation
security: isolate agent execution in a per-task sandbox worker - #716
Merged
Merged
Conversation
…ate backfill, and kernel kill-switch - Startup fail-closed: LockDownKeyDir explicitly chmods 0700 an existing key dir (counteracting host bind mounts) and 0600 existing key files; adds keys/ itself alongside jwt.key, secret.key, and config.json to IsolationSelfTest; makes IsolationSelfTest fatal unless ARTEX_ALLOW_UNISOLATED=1 is set. - Secret rotation: adds db.RotateSecretKey (single atomic transaction re-encrypting all sealed columns/settings and bumping auth.password_version), cmd/artex -rotate-secrets, scripts/rotate-secrets.sh, and OPS/SECURITY docs. - Scoped defaults, backfill & posture warnings: TargetGate defaults ON for tasks with CompanyIDs or InterceptRules (explicit opt-out persisted in tasks.target_gate_opt_out); migration 0022_target_gate_backfill.sql backfills existing active scoped tasks that did not explicitly opt out; egress-guard defaults to EGRESS_MODE=enforce when scope lists exist; loud startup warning when target gate or egress enforcement is off. - Kernel-backed local kill-switch: enables PR_SET_CHILD_SUBREAPER and scans /proc (without trusting agent-writable state) on Engine.Pause/BeginDelete to kill escaped setsid, nohup, and nested double-fork daemons (plus all execPriv.UID processes in isolated mode) within <= 5s with zero post-pause egress.
…s proxy
Introduce the sandbox MVP architecture separating panel credentials and
PostgreSQL access from model-controlled tool execution:
- Runner service (cmd/artex-runner, sandbox/) owning /var/run/docker.sock
behind bearer-token auth (ARTEX_RUNNER_TOKEN) with POST /v1/tasks/{id}/exec,
POST /v1/tasks/{id}/kill, DELETE /v1/tasks/{id}, and GET /v1/health.
- Strict input and env validation (400 on forbidden secret/DB/cloud env
patterns or values > 8192 bytes, strict task ID and /workspace workdir).
- Hardened per-task worker containers (Dockerfile.worker, artex-worker:local,
cmd/artex-exec-wrap): uid/gid 10001, artex-exec-wrap --init PID 1 zombie
reaper, read-only rootfs, cap-drop ALL, no-new-privileges, pids/mem/cpu
limits, tmpfs /tmp and /home/exec, only /app/data/tasks/<id>:/workspace:rw,
only verified internal=true runner-labeled network artex-task-<id>.
- Kernel-backed kill-switch (zero agent-writable state): Kill executes
artex-exec-wrap --kill-uid 10001 as uid 10001 scanning /proc directly
(defeating setsid, nohup, nested double-forked trap-TERM daemons, and /tmp
tampering), verifies zero non-PID-1 uid-10001 processes remain, and falls
back to force-removing the worker container if any check fails. Dead
workers/proxies are recreated automatically when startContainer fails.
- Operator-only scope approval (migration 0023_task_scope_operator_approval.sql):
adds task_scope.approved_by_operator BOOLEAN NOT NULL DEFAULT FALSE, set
true exclusively by operator API/UI (AddOperatorScope) and operator-selected
TaskCreateOptions.CompanyIDs (insertTaskCompanies). AddAgentScope and
AddAutoScope leave it false (coverage-only). taskSandboxRunInfo reads only
approved, non-expanded rows (and expands company scope only for approved
company rows); tasks with no approved scope deny all egress.
- Per-task egress proxy (cmd/artex-egress-proxy, Dockerfile.egress-proxy,
artex-egress-proxy:local): HTTP/HTTPS CONNECT (:3128) and SOCKS5 (:1080),
deny-by-default allowlist with strict domain suffix enforcement, blocks
RFC1918/loopback/link-local/IMDS and IPv6 unless in scope CIDRs, DNS
pinning, and tamper-proof JSONL audit logging to a proxy-only mount
(/app/data/egress-audit/<id>:/audit:rw) never mounted into the worker.
- Panel integration (agent/sandbox.go, agent/webfetch.go, server/sandbox.go,
server/sharedbrowser_guard.go, server/assembly.go, server/customtool.go,
docker-compose.sandbox.yml): ARTEX_SANDBOX defaults to required (fail closed,
no local fallback), WebFetch and opt-in shared browser inherit the
operator-approved sandbox.EgressPolicy (with target_gate or explicit proxy
required for shared browser), custom script tools staged via symlink-confined
workspace files (avoiding argv E2BIG), Pause/Stop/Delete wired to runner
Kill/Delete.
- Documented breaking change and hardening details in docs/SANDBOX.md,
README.md, and CHANGELOG.md.
BaaRai
force-pushed
the
sec/sandbox-mvp
branch
from
November 30, 2026 18:09
819f094 to
643e814
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Isolate model-controlled tool execution from the panel. Stacked on #715 (P0 hardening); merge after it.
The panel keeps the API, PostgreSQL, the keys and the LLM credentials. Every agent command runs in a disposable per-task worker container with no secrets, no panel or database route, and a per-task egress proxy. The worker can reach only what the operator approved.
What changes
artex-runnerowns the Docker socket, behind bearer-token auth. It creates one worker and one egress proxy per task. The panel never mounts the Docker socket and the worker cannot reach the runner.cap-drop ALL,no-new-privileges, pids/memory/CPU limits, tmpfs for/tmpand the executor home, only/app/data/tasks/<id>:/workspace:rw. No keys, config, DSN or LLM credentials.task_scopeis coverage scope and is agent-writable. Migration0023_task_scope_operator_approval.sqladdsapproved_by_operator. Only operator-approved rows (task scope UI, operator-selected companies, operator retarget) grant sandbox egress. Agentadd_task_scope, autoinsert_assets, agent-spawned company scope and expanded rows are coverage-only.WebFetchand the shared browser use the same policy.artex-exec-wrap --kill-uidscans/procfor every uid-10001 process and does not trust any agent-writable state. The runner force-removes the worker if a process survives, preserving the workspace.Breaking changes
ARTEX_SANDBOXdefaults torequired. Withoutartex-runner, tasks refuse to execute and pause with a clear error.ARTEX_SANDBOX=offis the explicit, loud degraded mode.docker-compose.sandbox.ymland worker/runner/proxy images are required for the sandbox.0023backfills operator-enteredsource='manual'scopes. Goal-derived (source='agent') and auto (source='auto') scopes must be re-approved once in Task Scope before sandbox egress is granted. This is fail-closed and documented indocs/SANDBOX.md.WebFetchand shared-browser egress still require an operator-approved Task Scope entry or a task allow rule. The denial message and the approval response state this explicitly.Tests
go build ./...,go vet ./...go test -p 1 ./...on PostgreSQL 16, 24/24 packagesgo test -race ./sandbox ./agent ./serversetsid,nohup, double forktrap '' TERM, egress loop), dead-worker recreationTestSandboxScopeDriftBlockedAcrossProxyWebFetchAndBrowser: agent/auto/manual-spoof/company rows denied across proxy, WebFetch and shared browser; operator rows and operator companies allowed; domain suffix enforcedReferences and credits
Implements the execution-scope design tracked in #421 and #423 by @youssefmedhatl, and #554, #555 and #553 by @renaesop, with the two-sources-of-truth analysis by @Dukotah in #421. The public writeup of 28 November 2026 confirmed the gap. The audit surface will continue in the follow-up tracked by #553.