Skip to main content

The Part of Your App You Can Hand to Something You Don't Trust

CJ Cummings
Creator and maintainer of Stof, co-founder & CEO of Limitr

Sometime in the last year, "the agent will just edit the file" stopped being hypothetical and became a normal workflow. Point an agent at a config, a document, or a blob of state, and it reads, edits, and writes it back, with no UI in between.

That's useful. It's also a trust problem most formats were never built to handle.

Two questions most formats can't answer​

When something you don't fully control edits your app's state directly, two questions come up right away:

  1. Can it leave the data broken? JSON doesn't know what a valid version of itself looks like. Validation lives somewhere else: a schema file, a Zod or Pydantic model, a check your app runs afterward. The data has no opinion.
  2. Can it reach further than it should? If the edit includes logic, like a new rule or a new function, what stops that logic from touching the file system, the network, or the rest of your app once it runs?

The usual answer to both is to trust more, not less: bundle the whole app, sign the release, keep a rollback plan. That works. It's also a lot of machinery just to make an edit safe to accept.

Let the data have an opinion​

Stof goes the other way. A Stof document validates itself: the rules live on the fields they protect, so an edit can be checked by the document before it's accepted. Press Run:

profile.stofPlayground ↗
#[type]
Profile: {
  #[schema((v: str): bool => v != null && v.len() > 1)]
  str name: 'Ada'

  #[schema((v: int): bool => v != null && v >= 0 && v < 150)]
  int age: 30
}

Profile user: { name: 'Ada', age: 30 }

/// Apply an edit only if the result is still a valid Profile.
fn apply(edit: obj) -> bool {
  const next = copy(self.user);
  for (const (field, value) in edit.fields()) next.set(field, value);
  if (!<Profile>.schemafy(next)) return false;
  self.user = next;
  true
}

#[main]
fn main() {
  pln(self.apply(new { age: -4 }));           // false: rejected, user unchanged
  pln(self.user.age);                         // 30

  pln(self.apply(new { name: 'Grace', age: 36 }));   // true: applied
  pln(self.user.name);                        // Grace
}
Output

The agent proposes an edit. The document checks it against its own rules. A bad edit is a false, not a corrupted file, and the rules travel with the data, so the check is the same whether the edit came from your UI, a model, or a customer.

And nothing to reach​

The second question has a one-word answer: there's nothing there. A document can see itself and the functions your app registers. Files, network, and environment don't exist to it unless you turn them on:

import { StofDoc } from '@formata/stof';

const doc = await StofDoc.new(state);

doc.lib('App', 'notify', (user: string, message: string) => notify(user, message));
doc.allowHttp(['api.example.com']); // this host, and no other
doc.setMaxExecutionTime(50); // every call fails after 50 ms

doc.parse(logicFromTheAgent); // a new rule goes in, with exactly those limits
await doc.run('on_update');

If the agent's rule tries to fs::read or fetch from anywhere else, it fails with an error that says the host hasn't allowed that. Not because a permission check ran and decided the code looked suspicious, but because there was nothing to call. The damage logic can do is bounded by what you gave it, not by how much you trust where it came from. (Security and the Sandbox has the whole model, including sealing the parts you don't want changed at all.)

Not the whole app, the part inside it​

It's tempting to read "portable, sandboxed, single document" and reach for something bigger: what if the whole app lived in a Stof file, UI and all?

That's the wrong shape. The moment a document has to draw pixels or drive a UI, it needs broad, standing access, and you're back to trusting the whole bundle, which is the problem the sandbox exists to avoid.

The useful version is narrower. The UI stays outside, doing what it's good at. The state, the rules, and what's allowed to happen live in a Stof document, because that's the part of the system that's safe to hand to something you don't fully trust. An agent can edit it. A plugin can extend it while it runs. Neither requires trusting the editor, only that the document can't be made invalid and can't reach further than you allowed.

More and more of an app's state is edited by something other than the app. The question isn't how to make the whole app safe to hand over. It's which part should be.

Rules a Model Writes walks through the full loop in the playground: a model writes logic, the document checks it, and only then does it run. How to Safely Give AI Agents New Tools at Runtime covers the logic side of the same idea.