APISDK setup

Lifecycle and configuration

Configure native storage, providers, execution policy, and orderly shutdown.

Keep one native installation open for the lifetime of the application that owns it.

Lifecycle

CallEffect
await createShip(options)Initialize the owned worker, storage, and providers.
await ship.start()Enable operations and any explicitly configured scheduling.
await ship.scope({ identity, organizationId })Create an authorized user/organization view.
await ship.close({ mode: "drain" })Refuse new mutations, drain owned work, and release resources.

Use try/finally around work or close during your application's shutdown. A scope does not own the installation. Closing an installation does not delete its database or project configuration.

Required configuration

OptionRequirement
instanceIdStable installation ID; reuse it when reopening.
stateDirectoryAbsolute private directory for source, releases, and provider state.
storageExplicit PGlite or PostgreSQL configuration.
encryptionKeyPersistent UTF-8 secret of 32–4096 bytes.
runtimebare, docker, or cloud.
identityTrusted identity adapter; see identity setup.

The database is bound to its installation ID and key fingerprint. A different ID or key is rejected when reopening. Storage never defaults to the CLI's existing database.

Storage

DriverConfigurationMigration behavior
PGlite{ driver: "pglite", dataDir: "/absolute/path/database" }Applies bundled migrations by default.
In-memory PGlite{ driver: "pglite", dataDir: "memory://" }Ephemeral state for tests or short-lived installations.
PostgreSQL{ driver: "postgres", url, migrations: "verify" }Verifies migrations by default; choose "apply" explicitly to apply them.

Use migrations: "verify" when reopening an already migrated installation. stateDirectory and PGlite's dataDir are separate settings. Preserve both and the encryption key for persistent use.

Providers and policy

OptionEffect
routing"managed" by default; "none" is available with the bare runtime.
cloudExplicit Cloud provider credentials and optional hosted configuration.
policy.allowHostExecutionAllow local builds, host administration, and host SSH facilities. Disabled by default.
policy.sourceRootsAbsolute directories from which native directory sources may be imported.
policy.allowLocalForwardingAllow loopback listeners that forward to authorized remote servers.
administrationExpose trusted ship.operator methods. Disabled by default.
jobsEnable the retained job/backup scheduler at startup. Disabled by default.
recovery"none" or exclusive recovery for an owned, file-backed PGlite process.
diagnostics"inherit", "stderr", or "silent" engine diagnostics.
environmentAdditional provider settings; reserved storage, identity, and ownership fields cannot be overridden.
callerTrusted call attribution: source ("api" or "cli") and userAgent. It does not grant permissions.

See compatibility before enabling scheduling or Cloud forwarding.

Shutdown deadlines

close({ mode: "drain", timeoutMs }) limits how long the caller waits. A timeout rejects that wait; owned work continues draining. Do not delete installation files while it is still closing.

Cancelling a deployment wait also stops observation only. Use deployment(id).cancel() to request execution cancellation and inspect its resulting status.

Attach to an existing kernel

Advanced hosts that already own a PlatformKernel can call createShip({ platform, identity }). This overload returns a synchronous facade. It does not start or close caller-owned resources. Most integrations should use the owned factory shown in native setup.

On this page