Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
feat(agent-cli): add --yolo mode to disable sandbox and auto-approve tools
Akarshan Biswas2101e65c36e3
diff --git a/src-tauri/src/bin/jan.rs b/src-tauri/src/bin/jan.rsindex 2e0a60a39..a88cf322a 100644--- a/src-tauri/src/bin/jan.rs+++ b/src-tauri/src/bin/jan.rs@@ -160,6 +160,9 @@ enum AgentCommands {/// Max turns (overrides [agent].max_turns; clamped 1..=400)#[arg(long)]max_turns: Option<u32>,+ /// Disable the sandbox and auto-approve every tool call (no prompts)+ #[arg(long)]+ yolo: bool,#[command(flatten)]providers: ProviderArgs,},@@ -179,6 +182,9 @@ enum AgentCommands {/// Image file to attach to the first message (repeatable)#[arg(long = "image")]images: Vec<String>,+ /// Disable the sandbox and auto-approve every tool call (no prompts)+ #[arg(long)]+ yolo: bool,#[command(flatten)]providers: ProviderArgs,},@@ -192,6 +198,9 @@ enum AgentCommands {/// Model ID (overrides [agent].model in agent.toml)#[arg(long)]model: Option<String>,+ /// Disable the sandbox and auto-approve every tool call (no prompts)+ #[arg(long)]+ yolo: bool,#[command(flatten)]providers: ProviderArgs,},@@ -387,7 +396,7 @@ async fn main() {api_key: None,}.into_overrides();- if let Err(e) = cli_agent_ui(".", None, None, None, Vec::new(), overrides).await {+ if let Err(e) = cli_agent_ui(".", None, None, None, Vec::new(), overrides, false).await {eprintln!("Error: {e}");std::process::exit(1);}@@ -442,6 +451,7 @@ async fn handle_agent(cmd: AgentCommands) {task,model,max_turns,+ yolo,providers,} => {cli_agent_run(@@ -450,6 +460,7 @@ async fn handle_agent(cmd: AgentCommands) {model,max_turns,providers.into_overrides(),+ yolo,).await}@@ -459,6 +470,7 @@ async fn handle_agent(cmd: AgentCommands) {model,max_turns,images,+ yolo,providers,} => {cli_agent_ui(@@ -468,6 +480,7 @@ async fn handle_agent(cmd: AgentCommands) {max_turns,images,providers.into_overrides(),+ yolo,).await}@@ -475,8 +488,9 @@ async fn handle_agent(cmd: AgentCommands) {project,task,model,+ yolo,providers,- } => cli_agent_step(&project, &task, model, providers.into_overrides()).await,+ } => cli_agent_step(&project, &task, model, providers.into_overrides(), yolo).await,AgentCommands::Status { project, providers } => {match cli_agent_status(&project, &providers.into_overrides()) {Ok(status) => {diff --git a/src-tauri/src/core/agent/commands.rs b/src-tauri/src/core/agent/commands.rsindex 12f73b120..1b40d3f02 100644--- a/src-tauri/src/core/agent/commands.rs+++ b/src-tauri/src/core/agent/commands.rs@@ -67,6 +67,7 @@ fn build_orchestration_args<R: Runtime>(permission_requests: Arc::new(Mutex::new(HashMap::new())),system_prompt_override: None,subagents_enabled: true,+ yolo: false,}}diff --git a/src-tauri/src/core/agent/loop.rs b/src-tauri/src/core/agent/loop.rsindex e2384aec2..b68530e3a 100644--- a/src-tauri/src/core/agent/loop.rs+++ b/src-tauri/src/core/agent/loop.rs@@ -65,6 +65,10 @@ pub(crate) struct OrchestrationArgs {/// Whether this run may dispatch subagents. `false` for child runs, which/// caps recursion depth at one (a subagent cannot spawn grandchildren).pub subagents_enabled: bool,+ /// `--yolo`: disable the sandbox/permission gate and auto-allow every tool+ /// call (built-in reads/writes/exec and MCP) without prompting. Inherited by+ /// dispatched subagents via the cloned parent args.+ pub yolo: bool,}#[async_trait]@@ -171,6 +175,7 @@ struct CompositeToolInvoker {permission_requests: PermissionRegistry,grants: std::sync::Mutex<crate::core::agent::tools::gate::SessionGrants>,subagents: Option<SubagentContext>,+ yolo: bool,}impl CompositeToolInvoker {@@ -359,7 +364,7 @@ impl ToolInvoker for CompositeToolInvoker {));continue;}- if self.grants.lock().unwrap().covers_mcp(name) {+ if self.yolo || self.grants.lock().unwrap().covers_mcp(name) {mcp_calls.push(tc.clone());continue;}@@ -396,6 +401,13 @@ impl ToolInvoker for CompositeToolInvoker {&self.permissions,&snapshot,);+ // --yolo suppresses every prompt (sandbox escape, write, exec) but+ // still honors HardDeny, so the `.jan/agent` restricted-path invariant+ // and explicit agent.toml denies hold.+ let decision = match decision {+ Decision::Prompt(_) if self.yolo => Decision::Allow,+ other => other,+ };if matches!(decision, Decision::Allow) && tool.capability == Capability::Read {let root = self.project_root.clone();read_futures.push(async move {@@ -529,6 +541,7 @@ pub(crate) async fn run_server_side_openai_orchestration(permission_requests: Arc::new(Mutex::new(HashMap::new())),system_prompt_override: None,subagents_enabled: false,+ yolo: false,};run_orchestration_streamed(&tx, json_body, &args).await}@@ -647,6 +660,7 @@ async fn orchestrate_inner(permission_requests,system_prompt_override,subagents_enabled,+ yolo,} = args;let messages_value = json_body@@ -835,6 +849,7 @@ async fn orchestrate_inner(permission_requests: permission_requests.clone(),grants: std::sync::Mutex::new(crate::core::agent::tools::gate::SessionGrants::default()),subagents,+ yolo: *yolo,};let result = run_turn_cycle(events,@@ -1426,6 +1441,7 @@ mod tests {permission_requests: registry,grants: std::sync::Mutex::new(SessionGrants::default()),subagents: None,+ yolo: false,}}@@ -1505,6 +1521,27 @@ mod tests {let _ = std::fs::remove_dir_all(&root);}+ #[tokio::test]+ async fn yolo_writes_without_prompting() {+ let root = unique_project_root();+ let (tx, mut rx) = mpsc::unbounded_channel();+ let registry: PermissionRegistry = Arc::new(Mutex::new(HashMap::new()));+ let mut invoker = build_prompting_invoker(root.clone(), tx, registry);+ invoker.yolo = true;++ let out = invoker.invoke(&[write_call()]).await.unwrap();++ assert_eq!(out.len(), 1);+ assert!(!out[0].content.starts_with("ERROR"), "unexpected: {}", out[0].content);+ assert_eq!(std::fs::read_to_string(root.join("out.txt")).unwrap(), "hi");+ // No permission prompt should have been emitted.+ assert!(+ !matches!(rx.try_recv(), Ok(StreamEvent::PermissionRequest { .. })),+ "yolo must not prompt for a write"+ );+ let _ = std::fs::remove_dir_all(&root);+ }+#[tokio::test]async fn prompt_deny_reports_error_and_skips_write() {let root = unique_project_root();diff --git a/src-tauri/src/core/cli/mod.rs b/src-tauri/src/core/cli/mod.rsindex 42182eb53..f08ca5b8e 100644--- a/src-tauri/src/core/cli/mod.rs+++ b/src-tauri/src/core/cli/mod.rs@@ -751,8 +751,9 @@ pub async fn cli_agent_run(model: Option<String>,max_turns: Option<u32>,overrides: ProviderOverrides,+ yolo: bool,) -> Result<(), String> {- run_agent_loop(project, task, model, max_turns, overrides).await+ run_agent_loop(project, task, model, max_turns, overrides, yolo).await}/// Single-turn run for debugging (`max_turns = 1`).@@ -761,8 +762,9 @@ pub async fn cli_agent_step(task: &str,model: Option<String>,overrides: ProviderOverrides,+ yolo: bool,) -> Result<(), String> {- run_agent_loop(project, task, model, Some(1), overrides).await+ run_agent_loop(project, task, model, Some(1), overrides, yolo).await}#[allow(clippy::too_many_arguments)]@@ -774,6 +776,7 @@ fn build_cli_orchestration_args(mcp_servers: crate::core::state::SharedMcpServers,mcp_settings: McpSettings,permission_requests: PermissionRegistry,+ yolo: bool,) -> OrchestrationArgs {OrchestrationArgs {client: reqwest::Client::new(),@@ -788,6 +791,7 @@ fn build_cli_orchestration_args(permission_requests,system_prompt_override: None,subagents_enabled: true,+ yolo,}}@@ -1001,12 +1005,19 @@ fn prepare_agent_session(model_override: Option<String>,max_turns_override: Option<u32>,overrides: ProviderOverrides,+ yolo: bool,) -> Result<AgentSession, String> {let project_root = resolve_project_root(project);ensure_project(&project_root)?;let cfg = load_agent_config(&project_root)?;let permissions = permissions_from(&cfg);+ if yolo {+ eprintln!(+ "WARNING: --yolo disables the sandbox. The agent can read, write, and run any command without asking for approval."+ );+ }+// Resolution order: --model flag, then agent.toml [agent].model, then the// desktop app's currently-selected model (synced from settings.json).let model = model_override@@ -1054,6 +1065,7 @@ fn prepare_agent_session(mcp_servers.clone(),mcp_settings,permission_requests.clone(),+ yolo,);Ok(AgentSession {@@ -1073,8 +1085,10 @@ fn prepare_agent_run(model_override: Option<String>,max_turns_override: Option<u32>,overrides: ProviderOverrides,+ yolo: bool,) -> Result<PreparedRun, String> {- let session = prepare_agent_session(project, model_override, max_turns_override, overrides)?;+ let session =+ prepare_agent_session(project, model_override, max_turns_override, overrides, yolo)?;let body = session.body(serde_json::json!([{ "role": "user", "content": task }]));Ok(PreparedRun {args: session.args,@@ -1091,6 +1105,7 @@ async fn run_agent_loop(model_override: Option<String>,max_turns_override: Option<u32>,overrides: ProviderOverrides,+ yolo: bool,) -> Result<(), String> {let PreparedRun {args,@@ -1098,7 +1113,7 @@ async fn run_agent_loop(permission_requests,router_task,mcp_task,- } = prepare_agent_run(project, task, model_override, max_turns_override, overrides)?;+ } = prepare_agent_run(project, task, model_override, max_turns_override, overrides, yolo)?;// Block until the local model is loaded (no-op for cloud models).await_router_task(router_task).await?;@@ -1137,8 +1152,9 @@ pub async fn cli_agent_ui(max_turns: Option<u32>,images: Vec<String>,overrides: ProviderOverrides,+ yolo: bool,) -> Result<(), String> {- let session = prepare_agent_session(project, model, max_turns, overrides)?;+ let session = prepare_agent_session(project, model, max_turns, overrides, yolo)?;// TUI threads persist under the project's .jan/agent dir, separate from the// desktop store, so continuing here never mutates desktop threads.let project_root = resolve_project_root(project);diff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rsindex 5fd47d97b..7337eb8ff 100644--- a/src-tauri/src/core/cli/tui.rs+++ b/src-tauri/src/core/cli/tui.rs@@ -1958,6 +1958,9 @@ pub async fn run(let repo_root = git::repo_root(&project_root);let mut app = App::new(model, max_turns, agent_dir, project_root, repo_root);app.args = Some(args.clone());+ if args.yolo {+ app.note("--yolo: sandbox disabled, all tool calls auto-approved without prompting");+ }for path in &initial_images {match load_image_file(path) {Ok(img) => app.pending_images.push(img),