Skip to main content

How do I…

The jobs people use Stof for. Each answer says how Stof does it and links to the doc. They all run on the same thing, a document your app loads and calls, so they combine: a customer's rules can be written by a model, sealed, checked by a schema, and sent to the browser.

Run code a model wrote, safely, in my app​

Parse what the model wrote into the document as untrusted, so nothing in it runs while it parses, and seal it to what it may read, the libraries it may use, and how long it may run. Then call it like any other function. It can't reach files, the network, or the environment unless you list them, and every call has a time and memory limit.

Docs: Confining code from somewhere else · Limits on every call

Have a model write a function once, then run it with no model​

Declare an intent: a function described by what it should do, like intent fn greet(name: str) -> str 'a short, friendly greeting';. The first call has a model write it in Stof, in a sandbox, and it's only kept once it passes your #[examples] and #[checks]. Every call after that is plain code: no model, no tokens.

Docs: Intents · Examples and checks

Give each customer their own rules, with no deploy​

Keep one document per customer with their rules, limits, and state. New logic goes in the same way new data does: parse new fields and functions into the live document. An agent can edit it, a person reviews the diff, and the next call behaves differently.

Docs: Parsing at runtime · Using Stof in your app

Generate a UI per account, safely​

Describe the view in the account's document with #[tag], #[attr], and #[text], and computed values from its real data. stringify('html', obj) renders it, and the output is safe to put on a page, whatever the document holds, including a view a model wrote.

Docs: Markup: html and xml

Run the same logic in the browser and on the server​

Install the package for each side (npm i @formata/stof, pip install stof, or cargo add stof) and load the same document. Send it as text or compact binary (bstf), with its data, functions, and fields as they are now, and it gives the same answer everywhere.

Docs: Install · Stof and bstf

Let a document call my app's functions​

Register your functions with the document under a library name you choose (doc.lib('App', 'notify', fn) in JavaScript and Python), and the document calls them as App::notify(..). A document can't call anything you didn't give it, and the error says so.

Docs: Giving documents your functions

Give an AI agent tools, written in Stof​

With the built-in AI package, tools are Stof functions: the agent calls them, and they run in the same sandbox. Tools from MCP servers work too.

Docs: Tools and agents · MCP servers

Validate data with rules that live next to it​

Declare a type with #[schema] rules on its fields, and check any object against it. A rule is a function, so it can be any check you can write, and it lives in the same document as the data.

Docs: Validating with schemas

Make a config that checks and computes itself​

Start from the JSON, YAML, or TOML you have (any JSON is already Stof), add computed values, units like 5min or 2GB, and schema checks, then export plain JSON, YAML, or TOML for whatever reads it.

Docs: Formats · Types & units

Know the logic running is the logic I shipped​

Seal the parts you trust so nothing changes them, and check their digest or a signature when you seal. If it doesn't match, nothing is sealed.

Docs: Sealing what you trust · Checking it's the logic you shipped

Test the rules​

Put #[test] functions next to what they check and run them with stof test, or from your app.

Docs: Testing

Not sure Stof fits? See Is Stof right for you?. Weighing another tool? See Stof, compared.