---
title: "Rust SDK"
description: "The Rust SDK wraps the Autohand Code CLI in JSON-RPC mode and exposes async, typed APIs for prompts, event streams, permissions, and structured output."
sidebar:
  label: "Rust"
seo:
  title: "Rust SDK | Autohand Code Agent SDK"
  description: "Use the Rust SDK to control Autohand Code agents from Tokio-based services, CLIs, desktop apps, and test harnesses."
---

:::note
**Repository:** [autohandai/code-agent-sdk-rust](https://github.com/autohandai/code-agent-sdk-rust). This SDK is in beta while the Agent SDK APIs stabilize. Pin commits or package versions in production.
:::

## Requirements

- Rust 1.80 or newer.
- Tokio runtime.
- Autohand Code CLI installed, authenticated, and configured.

## Install

```toml
[dependencies]
autohand-sdk = { git = "https://github.com/autohandai/code-agent-sdk-rust" }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
```

## Run your first agent [#first-agent]

Start with the high-level agent API when you want the SDK to own the run lifecycle and final result collection.

```rust
use autohand_sdk::{Agent, Config, Result};

#[tokio::main]
async fn main() -> Result<()> {
    let mut agent = Agent::create(
        Config::from_env()
            .with_cwd(".")
            .with_instructions("Review code with senior Rust judgement."),
    )
    .await?;

    let result = agent
        .run("List the main source files and tell me what looks risky.")
        .await?;

    println!("{}", result.text);
    agent.close().await?;
    Ok(())
}
```

## API shape

- High-level `Agent` and `Run` APIs for application workflows.
- Low-level `AutohandSdk` for direct JSON-RPC control.
- Typed `SdkEvent` helpers for message deltas, tool events, permissions, and errors.
- Structured JSON helpers through `run_json` and `JsonRunOptions`.

## Low-level control [#extra]

Use `AutohandSdk` when your host needs direct access to plan mode, model switching, permission responses, or raw JSON-RPC calls.

```rust
use autohand_sdk::{AutohandSdk, Config, PromptOptions, Result};

#[tokio::main]
async fn main() -> Result<()> {
    let mut sdk = AutohandSdk::new(Config::from_env().with_cwd("."));
    sdk.start().await?;
    sdk.set_plan_mode(true).await?;

    let mut events = sdk
        .stream_prompt("Create a discovery plan for this SDK change.", PromptOptions::default())
        .await?;

    while let Some(event) = events.recv().await {
        println!("{:?}", event?);
    }

    sdk.stop().await?;
    Ok(())
}
```

## Next steps

- Use [Quickstart](/agent-sdk/quickstart) for the cross-language setup flow.
- Open [Rust API](/agent-sdk/rust-api) for the reference surface.
- Read [Stream responses in real-time](/agent-sdk/io/streaming) and [Handle approvals and user input](/agent-sdk/io/approvals) for shared runtime behavior.
