Skip to content

feat: wire sandbox into runner for agent-submitted strategies#11

Open
MiaMakesItHappen wants to merge 2 commits into
mainfrom
nightly/2026-03-12-sandbox-wiring
Open

feat: wire sandbox into runner for agent-submitted strategies#11
MiaMakesItHappen wants to merge 2 commits into
mainfrom
nightly/2026-03-12-sandbox-wiring

Conversation

@MiaMakesItHappen
Copy link
Copy Markdown
Owner

What

Closes the gap between the existing sandbox wrapper and the actual backtest runner — submitted strategies now actually run sandboxed.

Changes

  • worker/runner.py: Added trusted: bool = True param to run_backtest(). When False, routes strategy execution through worker.sandbox.run_sandboxed() (process-level isolation, 60s timeout, blocked builtins) instead of bare exec().
  • api/main.py: Added _is_submitted_strategy() helper. When creating a run, passes trusted=False if the strategy file lives inside STRATEGIES_DIR (i.e. was submitted via POST /strategies/submit). Local file strategies (strategy_path requests) remain trusted.
  • requirements.txt: Added pytest and httpx so tests can actually run out-of-the-box.
  • tests/test_api.py: New end-to-end API test suite (9 tests) covering health, submit, dedup, validation, run flow, leaderboard, and the sandbox-wiring integration.

Test results

21 passed in 2.14s

Why

The sandbox wrapper existed but was never called for submitted code — submitted strategies ran with the same bare exec() as trusted local files. This PR closes that.

- worker/runner.py: add trusted=bool param to run_backtest(); route
  untrusted strategies through worker.sandbox.run_sandboxed() (process
  isolation + timeout) instead of bare exec()
- api/main.py: add _is_submitted_strategy() helper; pass trusted=False
  to run_backtest() when strategy path lives inside STRATEGIES_DIR
  (i.e. came via POST /strategies/submit)
- requirements.txt: add pytest==9.0.2 + httpx==0.28.1 (needed for tests)
- tests/test_api.py: new end-to-end API test suite (9 tests):
  health, submit, dedup, validation, run flow, leaderboard,
  and sandbox-wiring integration test

All 21 tests pass (12 sandbox unit + 9 API e2e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant