SDK v2 hosts the native Copilot runtime in your application process by default instead of starting a separate runtime process. Sessions, events, tools, hooks, and JSON-RPC framing remain the same.
warning
In-process hosting is not a sandbox and provides no crash isolation from the runtime. A native crash can terminate your application. Test startup, model turns, and shutdown on every operating system and architecture that you deploy.
In-process hosting is a good fit when:
Select an explicit stdio or TCP subprocess connection when crash isolation or per-client process configuration is required. Use a backend service when multiple application instances must connect to a shared runtime over TCP.
The SDK loads the Copilot runtime native library and binds its fixed C ABI. All SDK methods continue to use the existing Content-Length-framed JSON-RPC protocol over an in-memory connection.
flowchart LR
App["Your application"]
SDK["Copilot SDK client"]
FFI["C ABI connection"]
Runtime["Native Copilot runtime"]
App --> SDK
SDK -- "JSON-RPC frames" --> FFI
FFI --> Runtime
Runtime -- "Events and callbacks" --> FFI
FFI --> SDK
The runtime:
All SDKs expose an explicit in-process connection option. Some languages require additional build or package configuration.
| SDK | Connection option | Additional requirement |
|---|---|---|
| TypeScript | RuntimeConnection.forInProcess() | None when the package includes a compatible runtime bundle |
| Python | RuntimeConnection.for_inprocess() | Pre-download with python -m copilot download-runtime --in-process when runtime download is unavailable during startup |
| Go | copilot.InProcessConnection{} | Run the application bundler or supply a compatible runtime package; no build tag is needed |
| .NET | RuntimeConnection.ForInProcess() | Include the runtime assets acquired for the deployment RID |
| Rust | RuntimeConnection::for_in_process(Default::default()) | Included by the default bundled-in-process Cargo feature |
| Java | RuntimeConnection.forInProcess() | Add the matching platform runtime classifier; JNA is a transitive SDK dependency |
The native runtime bundle must match the host operating system, CPU architecture, and, on Linux, C library. Unsupported hosts fail during runtime resolution or startup instead of falling back to a child process.
Ordinary clients use in-process hosting without a connection option. Set it explicitly to ignore the environment override:
import { CopilotClient, RuntimeConnection } from "copilot-sdk-supercharged";
const client = new CopilotClient({
mode: "coding-agent",
runtime: RuntimeConnection.forInProcess(),
});
await client.start();
from copilot import CopilotClient, RuntimeConnection
client = CopilotClient(mode="coding-agent", runtime=RuntimeConnection.for_inprocess())
await client.start()
package main
import (
"context"
"log"
copilot "github.com/microsoft/copilot-sdk/go/v2"
)
func main() {
client := copilot.NewClient(&copilot.ClientOptions{
Mode: copilot.ModeCodingAgent,
Runtime: copilot.InProcessConnection{},
})
if err := client.Start(context.Background()); err != nil {
log.Fatal(err)
}
defer client.Stop()
}
client := copilot.NewClient(&copilot.ClientOptions{
Mode: copilot.ModeCodingAgent,
Runtime: copilot.InProcessConnection{},
})
if err := client.Start(context.Background()); err != nil {
log.Fatal(err)
}
defer client.Stop()
var client = new CopilotClient(new CopilotClientOptions
{
Mode = CopilotClientMode.CodingAgent,
Runtime = RuntimeConnection.ForInProcess()
});
await client.StartAsync();
let options = ClientOptions::new(copilot_sdk::ClientMode::CodingAgent).with_runtime(RuntimeConnection::for_in_process(
InProcessRuntimeOptions::default(),
));
let client = Client::start(options).await?;
import com.microsoft.copilot.rpc.CopilotClientMode;
import com.microsoft.copilot.CopilotClient;
import com.microsoft.copilot.rpc.CopilotClientOptions;
import com.microsoft.copilot.rpc.RuntimeConnection;
public class Example {
public void run() throws Exception {
CopilotClientOptions options = new CopilotClientOptions().setMode(CopilotClientMode.CODING_AGENT)
.setRuntime(RuntimeConnection
.forInProcess());
CopilotClient client = new CopilotClient(options);
client
.start()
.join();
}
}
COPILOT_SDK_DEFAULT_CONNECTION accepts inprocess or stdio, case-insensitively. Unset or empty selects in-process. An explicit connection wins, even over an invalid override; otherwise invalid values fail. Java configures subprocesses through RuntimeConnection.forSpawnedStdio() or RuntimeConnection.forSpawnedTcp().
Prefer explicit client configuration in application code. Use the environment variable when deployment configuration must select the transport without changing the application.
Clients that omit a connection now load native code into the application process. To retain an owned subprocess, select it explicitly:
| SDK | Subprocess selection |
|---|---|
| TypeScript | new CopilotClient({ mode: "coding-agent", runtime: RuntimeConnection.forSpawnedStdio() }) |
| Python | CopilotClient(mode="coding-agent", runtime=RuntimeConnection.for_spawned_stdio()) |
| Go | copilot.NewClient(&copilot.ClientOptions{Mode: copilot.ModeCodingAgent, Runtime: copilot.SpawnedStdioConnection{}}) |
| .NET | new CopilotClient(new CopilotClientOptions { Mode = CopilotClientMode.CodingAgent, Runtime = RuntimeConnection.ForSpawnedStdio() }) |
| Rust | Client::start(ClientOptions::new(ClientMode::CodingAgent).with_runtime(RuntimeConnection::SpawnedStdio(Default::default()))).await? |
| Java | new CopilotClient(new CopilotClientOptions().setMode(CopilotClientMode.CODING_AGENT).setRuntime(RuntimeConnection.forSpawnedStdio())) |
Alternatively, set COPILOT_SDK_DEFAULT_CONNECTION=stdio before starting the application. Existing explicit TCP and external-server connections retain their behavior. A missing native library or unsupported option never triggers an automatic subprocess fallback.
Environment maps and process working directories belong only to spawned connections. Clients using those options must select a subprocess or move process-wide configuration to the host before startup. Supported typed settings such as authentication, telemetry, and base directory still work. Session working directories are separate and remain supported.
Rust applications disabling default features must enable in-process (or local-runtime with an application-supplied runtime) to use the new default. Subprocess-only builds can retain bundled-cli or runtime and select RuntimeConnection::for_spawned_stdio(...) explicitly.
Java GraalVM native-image cannot use JNA callback upcalls. Select RuntimeConnection.forSpawnedStdio() or RuntimeConnection.forTcp(host, port) explicitly for those deployments.
The SDK converts supported typed client options into native runtime arguments and host-scoped environment values. Depending on the SDK, these options include:
The in-process runtime receives a host environment snapshot plus supported typed overrides. It does not mutate the host environment.
Configure working directories per session. Set genuinely process-wide values before creating the first in-process client.
Each SDK first looks for a compatible bundled or cached runtime library. You can set COPILOT_CLI_PATH to point into a compatible Copilot runtime package when you need to provide the runtime separately.
Only one native runtime library path and version can normally be loaded in a process. Starting another client with the same loaded library is supported, but attempting to load a different runtime library fails.
For production deployments:
Starting an in-process client loads the native library, creates a runtime host, opens an in-memory connection, and performs the normal SDK protocol-version handshake.
During graceful shutdown, the SDK:
The native library can remain loaded until the application process exits. Do not depend on unloading and replacing the runtime library after first use.
In-process hosting has these current constraints:
Can you improve this documentation? These fine people already did:
copilot-cli-release-app[bot], copilot-sdk-mirror-writer[bot], Jeremiah Isaacson & Patrick NikoletichEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |