Quant Buffet API
Sandbox rules
Allowed imports, builtins, limits, and error types.
Draft-preview and batch lab runs execute your code in `backtest/sandbox_runner.py`. Source is parsed with `ast`, stripped of bootstrap boilerplate, then `exec`'d with a restricted namespace.
Allowed import roots
backtest.*— data, engine, metrics, templates, universesnumpy/np,pandas/pdmath,json,typing,collections,dataclassesfunctools,itertools,datetime,re,statistics,decimal__future__
Blocked
- Standard library modules outside the allow-list (
os,sys,pathlib,subprocess, …). - Third-party packages (
requests,sklearn,matplotlib, …). - Calls to
eval,exec,compile,open,input,breakpoint. async/awaitsyntax.- Source files larger than 80 KB.
Safe builtins
A subset of Python builtins is injected: abs, min, max, sum, len, range, enumerate, zip, map, filter, sorted, container types, round, print, isinstance, hasattr, type, and common exceptions.
Runtime limits
| Limit | Value |
|---|---|
Max symbols in ASSETS | 15 |
| Min price history | 30 rows after load |
| Min equity curve length | 20 points after run |
| Equity chart points returned | 90 (downsampled) |
| Default backtest start (payload) | 2000-01-01 or lab UI date |
Common error types
| Type | Typical cause |
|---|---|
SyntaxError | Invalid Python; line number returned when available. |
ContractError | Missing make_on_day or wrong return shape. |
ValueError | Bad import, whitelist symbol, empty ASSETS, signal never ready. |
ImportError | Blocked module at runtime. |
RuntimeError | No price data loaded for any symbol. |