Bonzai Core Engine: A Router That Picks the Cheaper Sandbox, With One Rule That Cannot Fire

bonzai-core-engine is a public Python repository of mine under github.com/yethikrishna, a Flask backend with many service modules. I read services/intelligent_execution_router.py, about 790 lines. I did not run it, and its tests I did not read.

What it does

Given a task description and optional code, the router scores complexity from 0 to 10. For Python snippets it parses the AST, counts imports, and flags subprocess-style calls and exec, eval or compile. The base score comes from line count, file count, dependencies and system operations, then it is averaged with a model-written assessment and nudged up for high risk or for needs such as a database or network. A score of 3 or less goes to E2B, 7 or more goes to Scrapybara, and the middle defaults to E2B unless a keyword check finds a reason. The cost constants are 0.10 dollars an hour for E2B and 2.50 for Scrapybara.

Where it goes wrong

The middle band looks for phrases such as full environment, database, network, installation, deployment, multi-file and system operation in the factors the snippet analysis produced. Those factors are only a handful of fixed strings: High line count, Many dependencies, System command execution detected, Dynamic code execution and System operation in non-Python code. By my reading only the last one contains a phrase from the list, and it is produced only for non-Python code. So for Python code, which is the main case the AST branch handles, the keyword rule has nothing to match, and mid-range tasks fall to E2B whatever they need.

The savings figure has a similar problem. It takes each task's estimated duration, which was computed with the route's own startup time, and prices that same duration at the Scrapybara rate. It ignores the 60 second startup the model assumes for Scrapybara. The result is mostly the ratio of the two hourly constants, not a measured saving.

What I would change

My opinion: have the snippet analysis emit the same labels the router looks for, or replace the phrase search with named flags. Compute the Scrapybara comparison with its own duration formula. Add a test that feeds a mid-range Python snippet with a subprocess call and asserts the route. I have not checked whether the tests already cover this.

← back to the journal