There’s a second idea hiding inside the sandbox work from Part 1 and Part 2, and it’s the one I keep scratching my head on.
A lot of teams now run small pieces of code outside the database: serverless functions, usually JavaScript, that transform a payload or enrich a record and then disappear. They’re handy, but each one is another platform to deploy and secure, and another line on the bill. And the function almost always turns around and reads from the database anyway, so the data takes a round trip so that twenty lines of code can run.
So the question: if the database can already run model-written Python behind two walls, could it run your JavaScript functions too? And if it can, could an agent write and change those functions without anyone losing sleep?
JavaScript turns out to be the easier guest#
I compiled QuickJS-ng, a small embeddable JavaScript engine, to WebAssembly and ran it inside the same locked-down helper as the Python guest. A trivial call took about 12.5 ms, two to two and a half times faster than the Python guest, and the module is 1.29 MB against Python’s 19.3 MB. Same frozen clock, same lack of network, same kernel check before any input crosses.
The hostile tests change shape a little. QuickJS normally ships its own std and os modules and can import code from a URL, so the tests make sure all of that fails. Our guest never had those modules, which means there’s no “it used to work and now it’s blocked” run to point at. The proof that those tests can see a failure comes from control cases that succeed on purpose and from deliberately breaking the expected results to watch the check go red.
It’s still a probe. The module is just over the 1 MiB cap on modules, and that cap is there for a reason: validating a deeply nested module costs memory in proportion to its nesting, and a 4 MB test module of 1.38 million nested blocks needed about 352 MB just to validate. So JavaScript needs its own guest kind with its own pinned hash, checked before anything runs, rather than a bigger cap. It also brings the numbers problem along: a Postgres bigint past 2^53 has to cross as text and come back as a BigInt.
Who gets to change the function?#
Running a function safely is half the problem. A deployed function lives a long time and gets called a lot, and now an agent wants to edit it.
Where I’ve landed so far:
- Code moves between trust levels one way. Approved SQL is pinned by hash and runs as the app’s confined role. Agent-written code runs only in the sandbox, with no connection back to the database. Nothing an agent writes ever gets promoted into trusted SQL.
- A function version is the hash of its source. Every call logs the language, the source hash, the outcome, the time, the fuel and the sizes, and never the source, the input or the output. “Which version of this function produced this row?” becomes a query instead of an archaeology project.
- Agents draft, people deploy. The design calls for two people to approve every tool, and the abuse tests check that the agent proposing a change can’t approve its own work.
None of that is new machinery. It’s the same roles, audit and approval habits the database already enforces for everything else, pointed at code.
Safe is not the same as right#
This is the part I keep coming back to. Everything so far makes sure a function can’t escape or hog the box. None of it says the answer is correct. A function that returns plausible garbage safely and within budget is still returning garbage, and with an agent in the loop, nobody reads it before the next step acts on it.
Here’s how I think about what can be checked, from cheapest to hardest:
- Shape. Every function declares an output schema from a deliberately small vocabulary: objects, arrays, strings, integers, booleans and null, with bounds required on lists, integers capped at 2^53 and no floats at all. The database rebuilds the answer from that schema, so undeclared fields are dropped and wrong types fail, and the error names the schema path, never the value. That catches a lot of nonsense and says nothing about meaning.
- Provenance. For the database’s own built-in functions, the backend checks properties the honest code guarantees. A summarizer’s output may only use words that appear in its input, and every chunk a chunker returns has to be a contiguous piece of the input. That stops invented content cold. It doesn’t stop a misleading answer: the check accepts “Do invest in Acme, trust the team” stitched together from two different sentences. You can prove an answer didn’t make anything up, but you can’t prove it didn’t mislead.
- Behavior over time. This one is mostly an idea, not something built. Because a version is a hash and every call is logged, a new version can run beside the old one on the same inputs before it gets promoted, and the answers get diffed. The frozen clock makes a call much easier to replay. Fuel counts are deterministic for the same call, so a new version that suddenly burns ten times the work on the same input is worth a look even when its output seems fine.
- Judgment. You can ask another model whether an answer looks right. I’d use that as a flag and never as the gate. A model grading a model is one more untrusted answer, and whatever text fooled the first model gets a shot at the judge too.
Under all four sits a limit I don’t see going away: the agent that consumes the answer can be talked into believing it. Schemas, cleaning and caps stop crashes and smuggled text. They don’t stop persuasion.
Where my head is at#
The serverless pitch was “don’t run servers for small bits of code.” The in-database pitch is “don’t move the data for small bits of code.” I think the second one gets more interesting once agents are the ones writing the code, because the system that owns the data already owns the permissions, the audit trail and the approvals.
What’s missing is a good answer to “was it right?” My bet is that this, more than the sandbox, is the hard problem in agent infrastructure for the next few years. Walls are an engineering problem we mostly know how to solve. Knowing that the thing on the other side of the wall did its job correctly is a lot harder.
