# Introduction

URL: /docs
Markdown: /docs.md

> 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.

```sakura title="src/main.sak"
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:

- `greet` takes a `String` and returns a `String`. It has no `!`, so it is **pure**: it only
  computes a value. It cannot print, read files or call the network.
- `main` ends with `! {Console}`. The part after `!` lists the function's **effects**: the
  things it does besides returning a value. `main` may print to the console, and nothing else.
- The `test` lives next to the code and runs with `sakura test`.

Ready to try it? [Install](/docs/install) takes one command, and the
[Quickstart](/docs/quickstart) runs this program.

> **Stable**
>
> `v1.0.0` is the current release, and it is stable: what the [Stability](/docs/stability) page
> lists keeps working across 1.x, and a breaking change waits for 2.0. A security fix that has to
> break something comes with a migration in the [changelog](/changelog). Native, packages and
> workers are experimental and may change.

## Why a signature matters [#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.

```sakura title="src/users.sak"
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.** `Email` is a **refinement type**: a `String` plus a rule
  (at most 254 bytes, contains `@`). A value that breaks the rule never gets in.
- **uses only `Users`, `Clock` and `Random`.** It cannot reach the network, the file system
  or environment variables. `Users` is an effect this program declares itself.
- **fails only with `EmailTaken` or `Banned`.** `Fail<SignupError>` lists every expected
  error. There are no exceptions and no `null`.
- **returns a user with the same email.** The `ensures` line 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 [#what-you-get]

- **Effects you can see.** Everything a function does besides returning a value is listed
  after `!`. See [Effects](/docs/tour/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](/docs/tour/effects#failure-faile-and-error-unions).
- **Checked contracts.** `requires`, `ensures` and refinement types are checked at runtime in
  every build, and `sakura verify` can prove some of them ahead of time. See
  [Contracts](/docs/tour/contracts).
- **Limited access.** Under `sakura run`, a program reaches only the files, hosts and
  environment variables you list in `sakura.toml`. See [Capabilities and security](/docs/tour/capabilities).
- **No manual memory management.** No lifetimes and no borrow checker. Values never change
  under you. See [Memory model](/docs/tour/memory).
- **Tools for agents.** Errors come as JSON with suggested fixes, `?name` placeholders ask the
  compiler what fits, and the compiler runs as an MCP server. See [For Agents](/docs/agents).
- **One tool.** The `sakura` command checks, builds, runs, tests, formats and proves. See the
  [CLI reference](/docs/cli).

Programs run on JavaScript (the default) and WebAssembly. Compiling to a native executable is
[experimental](/docs/native).

## Where to go next [#where-to-go-next]

- [Quickstart](/docs/quickstart): Install the compiler, then create, test and run a first program.
- [Language Tour](/docs/tour/basics): Short pages that build up the language one idea at a time.
- [Build a server](/docs/server): An HTTP service from `sakura new api` to a container.
- [Why Sakura Lang](/docs/why-sakura-lang): The problem with agent-written code, and how the language answers it.
- [For Agents](/docs/agents): llms.txt, the MCP server, JSON diagnostics and typed holes.
- [FAQ](/docs/faq): Short answers to common questions.

Details for contributors: the [language design](https://github.com/icantcodefyi/sakuralang/blob/main/docs/design.md),
the [compiler](https://github.com/icantcodefyi/sakuralang/tree/main/compiler), the
[roadmap](/docs/roadmap) and [changes since 0.1.0](/docs/changes).
