Cortex SDK
The official Rust SDK for Cortex trusted native plugins.
cortex-sdk is the stable Rust facade for Cortex's native ABI. It lets a plugin author implement Tool and MultiToolPlugin, then export a C-compatible cortex_plugin_init entry point with export_plugin!. The daemon loads that function table, while Rust trait objects stay inside the plugin library.
The SDK is deliberately standalone. It does not depend on cortex-types, cortex-kernel, cortex-runtime, or any other Cortex workspace crate. Stable DTOs for invocation context, tool results, media attachments, tool effects, and runtime progress live in this crate. Cortex converts those DTOs to internal runtime types at the plugin boundary.
Process JSON plugins do not need this crate. Use process plugins for third-party and cross-language tools. Use cortex-sdk when the plugin is trusted local Rust code that should run in-process for lower latency or direct runtime callbacks.
Boundaries
| Boundary | Use when | Requires cortex-sdk |
Isolation |
|---|---|---|---|
| Process JSON | You want a simple, cross-language, child-process tool | No | A manifest-declared command per tool call |
| Trusted native ABI | You want a Rust shared library loaded by the daemon | Yes | In-process, trusted code |
Install The SDK
For a native plugin:
[]
= "1.6.2"
= "1"
The plugin crate should build a shared library:
[]
= ["cdylib", "rlib"]
Path 1: Process Plugin From Scaffold To Release
Use this path when you do not need native in-process execution.
Create The Scaffold
The scaffold contains:
cortex-plugin-hello/
├── manifest.toml
├── bin/
│ └── hello-tool
├── skills/
├── prompts/
└── README.md
manifest.toml declares the tool. bin/hello-tool receives one JSON request on stdin and writes one JSON result to stdout.
Implement The Tool
The process receives:
It may return a JSON string:
"Processed: hello world"
or an object:
Use is_error = true when the command completed but the result should be treated as a failed tool call.
Review And Test
review shows requested capabilities, sandbox posture, signature state, conformance state, and recommended risk policy. test runs the local conformance checks that should pass before a package is published.
Sign, Pack, Publish, Install
Create a publisher key once and keep the private key outside the repository:
Sign and pack each release:
Upload the .cpx and .sha256 files to a GitHub Release. Users can install the release by repository name:
or by explicit version:
For non-interactive install after reviewing the verified publisher fingerprint:
--yes does not bypass signature, hash, manifest, package, or archive safety checks. It only accepts the verified publisher key into the local trust store when policy allows that non-interactive trust decision.
Path 2: Trusted Native Plugin From Crate To Release
Use this path when the plugin is trusted Rust code and should run inside the Cortex daemon.
Create The Crate
Cargo.toml:
[]
= "cortex-plugin-native-hello"
= "0.1.0"
= "2024"
= "MIT"
= false
[]
= ["cdylib", "rlib"]
[]
= "1.6.2"
= "1"
Implement The Plugin
src/lib.rs:
use *;
;
;
export_plugin!;
Add The Manifest
manifest.toml:
= "native-hello"
= "0.1.0"
= "Example trusted native Cortex plugin"
= "1.6.2"
= "trusted_native"
[]
= ["tools"]
= false
[]
= "trusted_in_process"
[]
= "lib/libcortex_plugin_native_hello.so"
= "trusted_in_process"
= 1
The Linux shared library name is derived from the crate name with hyphens converted to underscores. For cortex-plugin-native-hello, Cargo writes target/release/libcortex_plugin_native_hello.so.
Build, Review, Test
When lib/ is missing, Cortex can auto-resolve the native library from target/release/ during install, signing, and packing as long as the manifest declares [native].library.
Sign And Pack
cortex plugin sign writes package.toml. cortex plugin pack includes supported package assets and rejects unsafe archive shapes. A packaged install verifies the signature before copying files.
Publish And Install
Create a GitHub Release named v0.1.0 and upload:
cortex-plugin-native-hello-v0.1.0-linux-amd64.cpx
cortex-plugin-native-hello-v0.1.0-linux-amd64.cpx.sha256
Users install:
Trusted native plugins require a daemon restart after install or replacement because the daemon keeps loaded shared libraries mapped for its process lifetime.
Runtime-Aware Tools
Tools that need runtime metadata can override execute_with_runtime:
The runtime surface can expose session id, canonical actor, transport source, foreground/background scope, progress updates, observer text, declared effects, and structured media.
Publishing cortex-sdk
Maintainers publish the SDK crate separately from the Cortex binary release:
The package must pass the repository Docker gate before publish. Once a version is uploaded to crates.io, it cannot be overwritten.
References
- API docs: https://docs.rs/cortex-sdk
- Runtime/plugin guide: https://github.com/by-scott/cortex/blob/main/docs/plugins.md