stock-bot/docs/development/backlog/tasks/A02.md

3.8 KiB

A02 — Isolate untrusted TypeScript strategy builds and decisions

Parent epic: E8. Priority/severity: P1 / High. Relative complexity: L. Recommended specialization: Process isolation/security.

Scheduling source of truth: manifest entry A02. No task is authorized until the plan is approved. Dependencies and decision references below describe the design; the manifest controls current readiness.

Evidence and root cause

Intended behavior and implementation scope

Compile/import AI artifacts only in an OS-restricted process/container without network, secrets, DB, broker access or full future dataset. Engine supervisor sends prefix-only context and receives intents through a small IPC protocol. Apply wall/CPU/memory limits; pin artifact dependencies. node:vm alone is not a security boundary.

Measurable benefit: Makes arbitrary AI code execution a contained research capability.

Exclusions

No speculative distributed infrastructure or weakened correctness gates.

Likely files and ownership

  • apps/stock/orchestrator/src/backtest/ (isolated strategy host)
  • apps/stock/web-api/src/services/ (artifact registration)
  • scripts/ (sandbox launch profile)

Write locks: sandbox-contract, worker-protocol. One agent owns this change. Lock names do not override actual overlapping files.

Dependencies and blockers

Implementation requires A01, S01, P01 integrated.

Architecture decisions: ADR-007. Agents may not independently amend their policies.

Parallel eligibility: only with disjoint actual files and reserved write locks; read FIRST-WAVE.md for the initial exact ownership boundaries.

Acceptance criteria

  • Malicious imports, filesystem/network/env probing and infinite loops fail safely without affecting the API/paper process.
  • Candidate cannot access future bars through files/native handles; only the supervisor owns financial engine and data.
  • Trusted reviewed artifact fast path is an explicit human promotion, never self-selected by code.

Mandatory tests

  • deny_network_secret_read_child_spawn, infinite_loop_kill, malformed_intent, future_context_exfiltration, worker_cleanup.
  • Sandbox availability check fails closed; benchmark IPC overhead separately from trusted NAPI path.

Apply the relevant quality gates; submit exact commands, outcomes and skipped checks. Named cases above are required regression scenarios, not claims that those tests already exist.

Regression risks and rollback

Native runtime/process privileges can invalidate the sandbox; independent security review required. Keep migrations additive and previous results readable. Do not add a switch that restores a correctness defect. Versioned cutover/migration is required only when persisted contracts or active engines change; never silently fall back to old economics.

Handoff

Report scope changes (if any), fixture expectations, API/schema changes, measurements, remaining limitations and commit/PR references once authorized. Request independent review; only the integration/planning owner may mark the manifest done.