SCUA

AI agents

Give a model tools, and sandbox what it writes.

An agent needs tools with an interface a model can read, a way to run generated code without risk to the machine, and conversations that hold no resources while they wait. SCUA has each of them built in.

tool.scua
import sys

record Args {
  a: int where a in 0:1000000,
  b: int where b in 0:1000000,
}

let args = sys.parse_args(Args)
sys.emit({ ok = true, sum = args.a + args.b })
$ echo '{"a":2,"b":3}' | scua tool.scua
{"ok":true,"sum":5}

$ scua tool.scua --a 1          # exit code 2, error on stderr
{"error":{"message":"sys.parse_args(Args): args.b is missing", …}}

With the agent you already have

A SCUA tool is a process your agent can call today

You do not have to rewrite an agent to use this. A tool written in SCUA takes JSON on stdin and writes one JSON value on stdout, so an agent in Python or TypeScript runs it like any other command and hands the model the schema from scua schema --portable. A model has not seen SCUA before, so scua pack writes the prompt pack that teaches it the language when you want it to write tools itself.

Tools

Declare a tool's arguments once, as a record

sys.parse_args reads a tool's arguments from JSON on stdin or from command-line flags, checks every rule on the record, and fills the defaults. The tool body only runs when the arguments are valid. The result is one JSON value on stdout. A failure is one JSON error on stderr, and the exit code says what kind it was.

The same record gives the schema the model reads. scua schema --portable writes JSON Schema in the subset that OpenAI's structured outputs and Anthropic's strict tool use both accept, so the interface and its description cannot drift apart.

  • Every bad argument can be reported at once, so the model fixes them in one reply
  • Diagnostics go to stderr, so stdout stays machine-readable
  • scua pack builds a prompt pack that teaches a model the language
Write tools for AI agents →
One record record Args { a: int where a in 0:10, b: int where b in 0:10, } schema JSON Schema what the model reads The model decides to call the tool {"a": 2, "b": 12} checks sys.parse_args(Args) runs every rule before the tool body starts … args.b violates Args's where rule (got 12) one JSON error on stderr, exit code 2, the body never ran the model reads the error and tries again
The record is the single description of the tool. The schema and the checks both come from it, so they cannot disagree.

Generated code

Run model-written code with no access

sandbox.run compiles a string of source, calls its main with the input you pass and gives you the answer. The code inside holds no grant: it cannot read a file, reach the network, read the environment or the clock. Only data crosses the boundary.

Every sandbox has a budget of operations and a memory cap. Code that loops forever or allocates without end is stopped, and your program receives an error that says which limit was hit.

Run untrusted code →
double.scua
import sandbox

let generated = "fn main(input)\n  return input * 2\nend\n"

match sandbox.run(generated, 21)
  Ok(answer) -> print(answer)
  Error(e)   -> print(`the code failed: {e.kind}`)
end
$ scua --allow-sandbox double.scua
42
code a player or a model wrote fn main(input) while true do input = input + 1 end end stopped here, between two operations Operations this turn 200,000 allowed 0 of 200,000 left Memory 4 MiB allowed Error(e) e.kind == "out_of_fuel" Your program gets a value back and carries on. The code inside cannot catch the stop, and it held no capability to begin with.
The default sandbox allows 200,000 operations a turn and 4 MiB of memory. Both are yours to set.

Whole tools

Give an agent's tool a folder, and nothing else

When an agent runs a whole script as a tool, the same rule applies one level up. The script starts with no access, and the command that runs it says what it may touch and how much work it may do.

A tool that reaches for something it was not given fails with a message naming the missing grant, which a model can read and act on.

$ scua --max-ops=10m --max-mem=64M \
       --allow-fs=./scratch tool.scua < in.json
Every grant, in the CLI reference →
A script code you did not write read a file open a connection read the environment run a command starts with nothing Files ./scratch the rest Networkany host, any port Environmentkeys, tokens, paths Other programsrunning a command --allow-fs=./scratch not grantednot grantednot granted the boundary: only a grant passes
A script starts with nothing a file a socket env vars a command stopped at the boundary: not granted Files --allow-fs=./scratch ./scratch everything else: not reachable Network Environment Programs Each refusal names the grant that is missing.
The host granted one folder. The script's other three requests stop at the boundary, and each error names the grant that is missing.

Sessions

A waiting conversation is one stored object

An agent conversation spends nearly all of its life waiting, for the user or for a model to finish. SCUA can freeze the whole session to a blob, state and history included, drop it from memory and keep it in object storage. When the reply arrives, the host loads the blob and hands over the answer.

The session script is ordinary code. It asks the model and matches on the result, and never learns that it was frozen in between.

Hibernate a session →
agent_session.scua
-- `model` is a module the host registers. The session asks, and the HOST
-- decides whether to keep it in memory while the model thinks, or to
-- freeze it and wake it later with the answer.
fn handler(state, question)
  match model.ask(question)          -- parks; the host performs the real call
    Ok(answer)  -> use(answer)
    Error(e)    -> reconcile(e)      -- e.kind == "interrupted" after a reload
  end
end
From the hibernation guide. It needs a host program,
so it has no Run button.
One session, over an afternoon time → messages in memory awake awake awake in storage asleep: one stored object asleep: one stored object While it sleeps there is no process and no memory held for it. The script never learns it was frozen, and carries on from where it was.
One session over an afternoon: three short bursts in memory, and the rest of the time asleep as a stored object.

Packages for agents

The pieces around the model

Call a model

@scua/llm is a client for chat APIs with a pure core, so the tests for your agent run offline.

Serve tools over MCP

@scua/agentserve builds servers for Model Context Protocol clients, with tools, resources and prompts declared as records.

Retrieval

@scua/rag chunks text and keeps a vector store. @scua/tokenizer counts tokens exactly and splits text to fit a context window.

Replay instead of calling out

@scua/vcr records HTTP once and replays it in tests, with secrets redacted by default.

All the AI and agent packages →

Write your first tool

The guide goes from the nine-line tool above to schemas, exit codes and reading files safely.