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

Run custom logic inside SurrealDB. Write functions in Rust, compile to WebAssembly, and execute with full query engine access - no microservices, no cold starts, no network hops.

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

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

SurrealDB extensions turn it into a programmable data and logic layer - perfect for agentic and AI-heavy workloads.

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

Call LLMs, embedding models, or GPU inference next to the data and write results back in the same statement. WebAssembly plugins run inference and write results in one atomic operation.

SurrealQL Query

SELECT *, mod::ml::embed(content) FROM docs

LLM

Embeddings

GPU

Atomic write-back

Learn more

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

WebAssembly runs close to the data with WASM sandbox isolation. No filesystem access, no network access - just compute next to the data.

WASM Runtime

Startup

<1ms

Latency

~native

Isolation

Full

Filesystem

Blocked

Network

Blocked

DB direct

Blocked

Learn more

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

Secure multi-tenant clusters with least-privilege execution. Each function can have its own permission expression evaluated at call time.

Namespace

Admin

Editor

Database

Read

Write

Execute

Function

PERMISSIONS WHERE $auth.role = 'admin'

Evaluated at call time

Learn more

WASM SANDBOXING

## Isolated by design

Each module call creates a fresh WASM instance with its own isolated memory. Modules can only interact with SurrealDB through explicit host functions - no filesystem, no raw network, no direct database access. Data crosses the boundary via serialisation.

![SurrealDB](https://surrealdb.com/assets/static/surrealdb-icon.C3ORaDk9.svg)

SurrealDB Engine

Query engine

Parses and executes SurrealQL

Transaction context

Shared ACID boundary

Host bridge

WASM Sandbox

WASM Sandbox

Module code

User-defined Rust compiled to WASM

Isolated memory

Own Store and Instance per call

No filesystem

No direct DB

No raw network

BUILD PIPELINE

## How extensions work

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

1

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"

2

Compile with SurrealDB CLI

surreal module

command

Rust code ready

to compile to WASM

Compiled extension

module

3

SurrealDB instance

Create file location with

DEFINE BUCKET

Access the compiled extension module with

DEFINE MODULE

4

Access functions inside SurrealDB

CREATE person

SET num = mod::test::return_ten();

SELECT

id,

mod::test::is_positive(num)

AS is_positive

FROM person;

ZERO-DOWNTIME UPGRADES

## Hot-load, no downtime

Deploy, upgrade, or roll back modules without restarting your instance. In-flight requests continue on the previous version while new requests automatically load the updated module from storage. No forced termination, no cold starts.

DEFINE MODULE OVERWRITE ml;

Cache invalidation

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

In-flight requests

Continue on Module v1

Arc<Runtime> stays valid

Complete normally

Old runtime dropped when done

New requests

Cache miss → load from bucket

Build new Runtime, cache it

Module v2 live

Zero downtime transition

TRANSACTION SAFETY

## Same transaction, same commit

When a module calls back into SurrealQL via the host bridge, it runs in the same transaction context as the query that invoked it. Module writes, host callbacks, and the original query all commit or roll back as a single atomic unit. No eventual-consistency bugs.

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

GET STARTED

## Start building extensions

Run AI and application logic inside SurrealDB with WebAssembly extensions.

![Samsung](https://surrealdb.com/assets/static/4c58b81e7b3c9466.C_Hv0eml.svg)![NVIDIA](https://surrealdb.com/assets/static/nvidia.DaIEuMil.svg)![Apple](https://surrealdb.com/assets/static/f7dc2519e0d212bc.Cn8MYAK7.svg)![Verizon](https://surrealdb.com/assets/static/18b99996c689000f.B5PQ-nI9.svg)![Tencent](https://surrealdb.com/assets/static/401d8346058682c8.DqM87mst.svg)

SOC 2 Type 2

GDPR

Cyber Essentials Plus

ISO 27001

[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","name":"SurrealDB","url":"https://surrealdb.com","logo":"https://surrealdb.com/assets/static/logo.BG7_TG2b.svg","description":"SurrealDB is the unified data layer for AI. 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"}]}
```
