---
title: "Extensions | SurrealDB"
description: "Run WebAssembly plugins inside SurrealDB. Write functions in Rust, compile to WASM, and execute with full query engine access. No microservices, no cold starts."
url: https://surrealdb.com/surrealdb/extensions
---

# Extensions

[Get started](https://studio.surrealdb.com/current/instances/deploy) [Read the docs](https://surrealdb.com/docs/learn/extensions)

**Rust.** Write your functions in Rust, with its types and tooling.

**WebAssembly.** Compile once and run inside the engine, sandboxed.

**Query access.** Full access to your data from within the function.

1. ![Babcock](https://surrealdb.com/assets/static/babcock.lo4rnVg1.svg)
2. ![ING](https://surrealdb.com/assets/static/ing.X3I6S3_V.svg)
3. ![British Airways](https://surrealdb.com/assets/static/british-airways.KEsZiwV-.svg)
4. ![Nvidia](https://surrealdb.com/assets/static/nvidia.DaIEuMil.svg)
5. ![Apple](https://surrealdb.com/assets/static/apple.D5pq4flY.svg)
6. ![SpaceX](https://surrealdb.com/assets/static/spacex.CQJEk-IL.svg)
7. ![Samsung](https://surrealdb.com/assets/static/samsung.CH-vQgnb.svg)
8. ![adidas](https://surrealdb.com/assets/static/adidas.DdTC5qhk.svg)
9. ![Tencent](https://surrealdb.com/assets/static/tencent.paQmLxyy.svg)
10. ![Alibaba](https://surrealdb.com/assets/static/alibaba.B16idgfM.svg)
11. ![PolyAI](https://surrealdb.com/assets/static/poly-ai.c3w_fAg6.svg)
12. ![Later](https://surrealdb.com/assets/static/later.Ds736jFO.svg)
13. ![Verizon](https://surrealdb.com/assets/static/verizon.BI7CajdX.svg)
14. ![Liberty Mutual](https://surrealdb.com/assets/static/liberty-mutual.B7qOU1pd.svg)
15. ![Walmart](https://surrealdb.com/assets/static/walmart.BjDg_Sr8.svg)
16. ![Carrier](https://surrealdb.com/assets/static/carrier.D21gC6NX.svg)
17. ![Saks Fifth Avenue](https://surrealdb.com/assets/static/saks-fifth-avenue.COIDpLSb.svg)
18. ![San Francisco Compute Company](https://surrealdb.com/assets/static/sfcc.B7jlImq4.svg)
19. ![Shield AI](https://surrealdb.com/assets/static/shield-ai.pINZ0KJr.svg)
20. ![Wix](https://surrealdb.com/assets/static/wix.DvHhmoBi.svg)

## Run extensions inside SurrealDB. A programmable data and logic layer for agentic and AI-heavy workloads.

[Read the docs](https://surrealdb.com/docs/learn/extensions)

### [AI-ready by design](https://surrealdb.com/docs/learn/extensions)

Call LLMs, embedding models or GPU inference next to the data and write the result back in the same statement.

Explore extensions

### [Near-native performance](https://surrealdb.com/docs/surrealdb/extensions/plugins)

WebAssembly runs close to the data inside a sandbox: compute beside the records, and nothing else.

Explore plugins

### [Fine-grained governance](https://surrealdb.com/docs/learn/security)

Least-privilege execution for multi-tenant clusters, with a permission expression per function.

Explore security

01 |WASM SANDBOXING

## Isolated by design

Each call creates a fresh WASM instance with its own memory. A module reaches SurrealDB only through explicit host functions, and data crosses the boundary by serialisation.

SurrealDB Engine

Query engine

Parses and executes SurrealQL

Transaction context

Shared ACID boundary

WASM Sandboxno filesystem · no direct DB · no raw network

Module code

User-defined Rust compiled to WASM

Isolated memory

Own store and instance per call

02 |BUILD PIPELINE

## How extensions work

Write in Rust, compile to WebAssembly with the SurrealDB CLI, load into your instance, call from SurrealQL.

Functions

fn return_ten() -> i32 { 10 } fn is_positive(n: i32) -> bool { n >= 0 }

Use #[surrealism] to expose functions:

#[surrealism] fn return_ten() -> i32 { 10 } #[surrealism] fn is_positive(n: i32) -> bool { n >= 0 }

surrealism.toml

[package] organisation = "surrealdb" name = "demo" version = "1.0.0"

Compile with SurrealDB CLI

surreal module

command

Rust code ready

to compile to WASM

Compiled extension

module

SurrealDB instance

Create file location with

DEFINE BUCKET

Access the compiled extension module with

DEFINE MODULE

Access functions inside SurrealDB

CREATE person SET num = mod::test::return_ten(); SELECT id, mod::test::is_positive(num) AS is_positive FROM person;

03 |ZERO-DOWNTIME UPGRADES

## Hot-load, with the instance up

Deploy, upgrade or roll back a module on a running instance. In-flight requests finish on the previous version while new requests load the update from storage.

DEFINE MODULE OVERWRITE ml;

Cache invalidation

cache.remove(&lookup) - evicts the compiled Runtime

In-flight requests

Continue on Module v1 Arc<Runtime> stays valid

New requests

Cache miss → load from bucket Build new Runtime, cache it

Complete normally

Old runtime dropped when done

Module v2 live

Zero downtime transition

04 |TRANSACTION SAFETY

## Same transaction, same commit

A module that calls back into SurrealQL runs in the transaction that invoked it, so its writes, the host callbacks and the original query commit or roll back as one.

CREATE person SET score = mod::ml::predict(data);

Single ACID transaction

Query engine

Parses SurrealQL, finds mod::call

WASM module executes

mod::ml::predict() runs in sandbox

Host callback

__sr_sql("SELECT * FROM training_data") Runs in same ctx and opt - same transaction

Result returned

Module returns prediction, query continues

COMMIT

Query + module writes + host callbacks - one atomic unit

THE PLATFORM

## Everything an application and its agents know. Five surfaces, one engine.

Database

Document, graph, vector, time-series and relational in one engine.

![Five data models as dotted tiles: documents, graph, vector, time-series and relational](https://surrealdb.com/assets/static/platform-database.DUdumYDz.avif)

Read more

[Database](https://surrealdb.com/surrealdb)

Agent Memory

What an agent learns, with its source and its time, in the same engine.

![A timeline of remembered facts, each with its source](https://surrealdb.com/assets/static/platform-agent-memory.Cvv8D5Wl.avif)

Read more

[Agent Memory](https://surrealdb.com/agent-memory)

Cloud

Managed clusters in the regions you choose, scaled on demand.

![Clusters in three regions on a world map, each running or scaling](https://surrealdb.com/assets/static/platform-cloud.--QZnaVi.avif)

Read more

[Cloud](https://surrealdb.com/cloud)

Studio

Query, explore and design the schema from the browser.

![A SurrealQL query in Studio and the schema graph under it](https://surrealdb.com/assets/static/platform-studio.7ykBFNLq.avif)

Read more

[Studio](https://surrealdb.com/studio)

MCP

Every model that speaks MCP reaches the database and the memory directly.

![Three models connected through MCP to the database and Agent Memory](https://surrealdb.com/assets/static/platform-mcp.D_oH0_wm.avif)

Read more

[MCP](https://surrealdb.com/mcp)

IN PRODUCTION

## Trusted at scale. Samsung, Nvidia, Verizon, Tencent, and Walmart run on SurrealDB.

14,000+

Developers building on SurrealDB Cloud

4M+

Developers building on SurrealDB worldwide

FROM THE TEAMS

> SurrealDB gives us a foundation where we can unify semantic search, knowledge graphs, and AI-driven decision making without stitching together multiple systems. Collapsing responsibility into SurrealDB has become our default engineering posture.

*Justin Foley*

VP of Engineering, Later

GET STARTED

## Start building extensions. AI and application logic inside SurrealDB, as WebAssembly.

[Read the docs](https://surrealdb.com/docs/learn/extensions) [Start free with SurrealDB](https://studio.surrealdb.com/current/instances/deploy)

```json
{"@context":"https://schema.org","@type":"Organization","@id":"https://surrealdb.com/#organization","name":"SurrealDB","url":"https://surrealdb.com","logo":"https://surrealdb.com/assets/static/logo.BG7_TG2b.svg","description":"SurrealDB is the context and memory layer for AI agents. A multi-model database for documents, graphs, vectors, and time-series.","foundingDate":"2022","legalName":"SurrealDB Ltd","identifier":{"@type":"PropertyValue","propertyID":"GB-COH","value":"13615201"},"address":{"@type":"PostalAddress","streetAddress":"3rd Floor, 1 Ashley Road","addressLocality":"Altrincham","addressRegion":"Cheshire","postalCode":"WA14 2DT","addressCountry":"GB"},"contactPoint":[{"@type":"ContactPoint","contactType":"customer support","email":"support@surrealdb.com","url":"https://surrealdb.com/contact","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"sales","email":"info@surrealdb.com","url":"https://surrealdb.com/contact","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"security","email":"security@surrealdb.com","url":"https://surrealdb.com/.well-known/security.txt","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"legal","email":"legal@surrealdb.com","url":"https://surrealdb.com/legal","availableLanguage":"English"}],"hasCertification":[{"@type":"Certification","name":"SOC 2 Type 2"},{"@type":"Certification","name":"GDPR"},{"@type":"Certification","name":"Cyber Essentials Plus"},{"@type":"Certification","name":"ISO 27001"}],"owns":[{"@type":"SoftwareApplication","name":"SurrealDB","url":"https://surrealdb.com/surrealdb"},{"@type":"SoftwareApplication","name":"Agent Memory","url":"https://surrealdb.com/agent-memory"}],"knowsAbout":["multi-model databases","document databases","graph databases","vector search","time-series databases","SurrealQL","Agent Memory","real-time databases","embedded databases","context layer","graph ontology","distributed database","knowledge graphs","distributed transaction protocols","highly-scalable databases"],"sameAs":["https://www.wikidata.org/wiki/Q124316308","https://github.com/surrealdb/surrealdb","https://twitter.com/surrealdb","https://www.youtube.com/@surrealdb","https://www.linkedin.com/company/surrealdb","https://discord.gg/surrealdb","https://www.reddit.com/r/surrealdb","https://www.instagram.com/surrealdb","https://medium.com/surrealdb","https://dev.to/surrealdb"]}
```

```json
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://surrealdb.com"},{"@type":"ListItem","position":2,"name":"SurrealDB","item":"https://surrealdb.com/surrealdb"},{"@type":"ListItem","position":3,"name":"Extensions","item":"https://surrealdb.com/surrealdb/extensions"}]}
```
