Captain / Documentation / Part 7. Embedding Captain

Embedding Captain in Rust

Contents ↓

A Captain program does not have to run from the captain command. A Rust program can load a compiled .capb artifact, check it, hand it values and read back the result, through one crate: captain-sdk.

The SDK is the boundary for values crossing into and out of Captain. Captain's own hosts (the app host, the worker host, Forge and Bosun) convert their values through the same code, so a record your program passes in is checked exactly as the request record a worker receives.

The SDK has separate profiles. Each is a contract of its own, with its own claims and its own limits:

Profile Runs Chapter
captain.pure/1 one effect-free entry point of a .capb artifact 1 to 3
captain.local-process/1 one exact native executable, under a policy the host owns 4
captain.command-resolution/1 and captain.local-process/2 a developer command found on a frozen PATH, then run as above 4
captain.authenticated-command-evidence/1 no run: a checked projection of a recorded command run 4

Most embedders want the pure profile. It is how an application uses Captain for calculations it can audit: pricing, totals, eligibility rules, anything where the same inputs must always give the same answer and someone may later ask you to prove it.

Chapters

  1. The pure profile: load an artifact, list its entry points, plan a call, run it and read the result.
  2. Values in and out: scalars, lists, records and options as inputs; records, variants and options as results.
  3. Limits, run records and errors: the bounds a plan freezes, the outcomes, the run record and how to verify it, the CAP-SDK-* codes, and which VM generations the SDK runs.
  4. Process and command profiles: an overview of the profiles that run native programs.

What you need

  • The crate captain-sdk, version 0.7.0, which this part documents (see Versions and VM generations). It is distributed through the platform's private package registry, not crates.io.
  • A .capb artifact, built with captain build (see The toolchain).

The SDK does not compile Captain source. You build the artifact first, ship its bytes with your application, and the SDK verifies them every time it loads them.