supercode-harness 0.4.6

The optional native Supercode agent and tool harness
Documentation
//! Cookbook 03 — the OS process sandbox, offline.
//!
//! supercode confines tools two ways: the file tools honor the policy, and on
//! macOS the `bash` tool is wrapped in seatbelt so even an arbitrary shell
//! command cannot escape it. This example runs the same write under three
//! policies and shows what each allows. No API key — it calls the tool directly.
//!
//! ```sh
//! cargo run -p supercode-harness --example 03_sandbox
//! ```

use supercode_harness::tools::{BashTool, SandboxPolicy, Tool, ToolContext};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let dir = std::env::temp_dir().join(format!("sc-cookbook-sandbox-{}", std::process::id()));
    std::fs::create_dir_all(&dir)?;
    let bash = BashTool::default();

    for policy in [
        SandboxPolicy::ReadOnly,
        SandboxPolicy::WorkspaceWrite,
        SandboxPolicy::DangerFullAccess,
    ] {
        let mut ctx = ToolContext::new(dir.clone());
        ctx.sandbox = policy;
        let marker = dir.join("written.txt");
        let _ = std::fs::remove_file(&marker);

        bash.execute(
            serde_json::json!({ "command": "echo hi > written.txt" }),
            &ctx,
        )
        .await?;

        let landed = marker.exists();
        println!(
            "{:<18} write inside cwd → {}",
            format!("{policy:?}"),
            if landed { "ALLOWED" } else { "blocked" }
        );
    }

    std::fs::remove_dir_all(&dir).ok();
    println!("\nOn macOS the block is enforced by the OS (seatbelt), not just the file tool.");
    Ok(())
}