Introduction
Sakura Lang is a programming language for code that AI agents write and people review. Every function says what it can do, and the compiler checks it.
Sakura Lang is a programming language for code that AI agents write and people review. Every function's signature says what the function can do. The compiler checks that the body does nothing more.
fn greet(name: String) -> String { "Hello, {name}" }
pub fn main() -> Unit ! {Console} { Console.print(greet("world")) }
test "greets by name" { expect_eq(greet("Ada"), "Hello, Ada") }sakura run prints Hello, world. Here is what each line says:
greettakes aStringand returns aString. It has no!, so it is pure: it only computes a value. It cannot print, read files or call the network.mainends with! {Console}. The part after!lists the function's effects: the things it does besides returning a value.mainmay print to the console, and nothing else.- The
testlives next to the code and runs withsakura test.
Ready to try it? Install takes one command, and the Quickstart runs this program.
Why a signature matters
Agents can write thousands of lines an hour. Nobody can review all of it line by line. In most languages, the important facts about a function are hidden in its body: whether it touches the network, how it can fail, what it guarantees.
Sakura Lang puts those facts in the signature. You review the signature, which is short. The compiler checks the body, which is long.
Here is a bigger example: signing up a user.
type Email = String where String.len(it) <= 254 && String.contains(it, "@")
type User = { id: Uuid, email: Email, created: Instant }
error EmailTaken(email: Email)
error Banned
type SignupError = EmailTaken | Banned
effect Users {
fn email_exists(email: Email) -> Bool
fn is_banned(email: Email) -> Bool
fn insert(user: User) -> Unit
}
fn signup(email: Email) -> User ! {Users, Clock, Random, Fail<SignupError>}
ensures result.email == email
{
if Users.is_banned(email) { fail Banned }
if Users.email_exists(email) { fail EmailTaken { email } }
let user = User { id: Random.uuid(), email, created: Clock.now() }
Users.insert(user)
user
}
fn memory_users() -> Handler<Users> {
handler Users {
var users: List<User> = List.empty()
fn email_exists(email) { List.any(users, fn(u) { u.email == email }) }
fn is_banned(email) { false }
fn insert(user) { users = List.push(users, user) }
}
}
test "duplicate email fails" {
with memory_users() {
let _ = signup(Email.from("a@b.co"))
expect_fail(fn() { signup(Email.from("a@b.co")) }, EmailTaken { email: Email.from("a@b.co") })
}
}Read only the signature of signup, and you know that it:
- accepts only a valid email.
Emailis a refinement type: aStringplus a rule (at most 254 bytes, contains@). A value that breaks the rule never gets in. - uses only
Users,ClockandRandom. It cannot reach the network, the file system or environment variables.Usersis an effect this program declares itself. - fails only with
EmailTakenorBanned.Fail<SignupError>lists every expected error. There are no exceptions and nonull. - returns a user with the same email. The
ensuresline is a contract: a rule about the result, checked every time the function returns.
The test swaps in memory_users(), a handler: code that decides what an effect does when
it runs. In production, a handler could talk to a database. In the test, it keeps a list in
memory. Tests also get a fixed clock and seeded randomness for free, so no mocking library is
needed.
What you get
- Effects you can see. Everything a function does besides returning a value is listed
after
!. See Effects. - Errors as values. Expected failures are typed, and the compiler makes you handle them. Bugs such as integer overflow stop the program with a clear report. See Effects.
- Checked contracts.
requires,ensuresand refinement types are checked at runtime in every build, andsakura verifycan prove some of them ahead of time. See Contracts. - Limited access. Under
sakura run, a program reaches only the files, hosts and environment variables you list insakura.toml. See Capabilities and security. - No manual memory management. No lifetimes and no borrow checker. Values never change under you. See Memory model.
- Tools for agents. Errors come as JSON with suggested fixes,
?nameplaceholders ask the compiler what fits, and the compiler runs as an MCP server. See For Agents. - One tool. The
sakuracommand checks, builds, runs, tests, formats and proves. See the CLI reference.
Programs run on JavaScript (the default) and WebAssembly. Compiling to a native executable is experimental.
Where to go next
Quickstart
Install the compiler, then create, test and run a first program.
Language Tour
Short pages that build up the language one idea at a time.
Build a server
An HTTP service from sakura new api to a container.
Why Sakura Lang
The problem with agent-written code, and how the language answers it.
For Agents
llms.txt, the MCP server, JSON diagnostics and typed holes.
FAQ
Short answers to common questions.
Details for contributors: the language design, the compiler, the roadmap and changes since 0.1.0.
Last updated