Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

feat(agent): let a sandboxed shell command escalate out of the sandbox with user approval (#9239)

Akarshan Biswas2ba3c5ca2c60
diff --git a/adk/python/jan_adk/_generated.py b/adk/python/jan_adk/_generated.py
index 1fc70f72b..101d2cc03 100644
--- a/adk/python/jan_adk/_generated.py
+++ b/adk/python/jan_adk/_generated.py
@@ -473,6 +473,8 @@ class PermissionRequestEvent(TypedDict):
diff: NotRequired[Union[str, None]]
prompt_kind: str
offers_always: bool
+ # The model's reason for an `escalate` prompt (running a shell command outside the sandbox), shown beside the command; `None` otherwise.
+ justification: NotRequired[Union[str, None]]
type: Literal["permission_request"]
class ToolRequestEvent(TypedDict):
diff --git a/docs/src/pages/docs/agent/cli.mdx b/docs/src/pages/docs/agent/cli.mdx
index ba2ccf6ce..4c1bb5777 100644
--- a/docs/src/pages/docs/agent/cli.mdx
+++ b/docs/src/pages/docs/agent/cli.mdx
@@ -39,6 +39,7 @@ jan <COMMAND>
| `--safe` | Ask for approval before writes, shell commands, and MCP tool calls |
| `--sandbox` | Run shell commands under OS confinement. Off by default |
| `--no-sandbox` | Run shell commands unconfined, overriding a persistent `sandbox` setting |
+| `--allow-escalation` | Let a sandboxed shell command that asks to leave the sandbox run without an escalation prompt (`--safe` still asks once). See [Running a command outside the sandbox](/docs/agent/permissions#running-a-command-outside-the-sandbox) |
| `--resume [ID]` | Resume the most recent session, or one whose id starts with `ID` |
| `-c`, `--continue` | Resume the most recent session |
| `--fork-session` | Open the resumed session as a new thread, leaving the original resumable |
@@ -100,6 +101,7 @@ jan cli agent run --max-turns 5 --max-session-tokens 20000 "triage the build fai
| `--safe` | Ask for approval before writes, shell commands, and MCP tool calls |
| `--sandbox` | Run shell commands under OS confinement. Off by default |
| `--no-sandbox` | Run shell commands unconfined, overriding a persistent `sandbox` setting |
+| `--allow-escalation` | Let a sandboxed shell command that asks to leave the sandbox run without an escalation prompt (`--safe` still asks once). See [Running a command outside the sandbox](/docs/agent/permissions#running-a-command-outside-the-sandbox) |
| `--resume[=ID]` | Resume the most recent session, or one by id |
| `-c`, `--continue` | Resume the most recent session |
| `--fork-session` | Open the resumed session as a new thread, leaving the original resumable |
diff --git a/docs/src/pages/docs/agent/permissions.mdx b/docs/src/pages/docs/agent/permissions.mdx
index aaebec9f1..7a21628f7 100644
--- a/docs/src/pages/docs/agent/permissions.mdx
+++ b/docs/src/pages/docs/agent/permissions.mdx
@@ -155,6 +155,54 @@ permanently would leave no way to run a single command without it.
`backend` is the confinement that *would* be used. `none` means none is available on this machine -
with `enabled: true` that combination is what withholds `shell` entirely.
+### Running a command outside the sandbox
+
+Some everyday commands write outside the project: `cargo build` fills `~/.cargo/registry`, and
+`pip`, `npm` and `go` write their caches under your home directory. Inside the sandbox these fail
+with a read-only file system error. When that happens to a command the task needs, the agent can
+ask to rerun it **outside** the sandbox. It sets `escalate` on the shell call and gives a one-line
+reason, and you are asked:
+
+```
+shell wants exec outside the sandbox
+$ cargo build
+why cargo needs to write ~/.cargo/registry to fetch crates
+> Allow once
+ Deny
+```
+
+An approved command runs with your own access, like a command you typed. The minimal environment
+(below) still applies. Escalation is deliberately stricter than every other prompt:
+
+- **It is never auto-approved.** Running without `--safe` approves tools that run *inside* the
+ sandbox, not a request to leave it, so the prompt still appears.
+- **There is no "allow always".** Each escalation is answered on its own.
+- **Where nobody can answer, it is refused.** That covers a headless `jan cli agent run` reading
+ from a pipe or CI, and a subagent whose parent cannot be asked. The command does not run at all,
+ and the model is told how you could enable it.
+- **The desktop never escalates.** Its chat sandbox is throwaway by design.
+- An escalated command runs outside the sandbox, so `~/.jan` is **not** hidden from it. A command
+ that names `~/.jan` outright is refused before anyone is asked, but that check only reads the
+ command text: a command that reaches the folder indirectly (`cd ~ && cat .jan/config.toml`)
+ gets past it, and could read your provider keys. Read the command before you approve it.
+
+For unattended runs that accept the risk, allow escalation without a prompt. Nobody then reads
+the command, so any escalated command can reach everything you can, `~/.jan` included:
+
+```bash
+jan cli agent run --sandbox --allow-escalation "..."
+```
+
+```toml
+# ~/.jan/projects/<slug>/agent.toml
+[tools]
+allow_escalation = true
+```
+
+This drops only the escalation prompt. With `--safe`, a shell command still needs your approval
+whether or not it escalates, so you are asked once (about running it outside the sandbox) rather
+than not at all. Adding `escalate` never gets a command past an approval it would otherwise need.
+
### Which shell runs commands
On macOS and Linux the `shell` tool runs `bash` (or `sh` where there is none). On Windows it runs
diff --git a/packages/adk/src/generated/rpc-types.d.ts b/packages/adk/src/generated/rpc-types.d.ts
index 6dbf4aeb7..39a2a06bc 100644
--- a/packages/adk/src/generated/rpc-types.d.ts
+++ b/packages/adk/src/generated/rpc-types.d.ts
@@ -441,6 +441,8 @@ export interface PermissionRequestEvent {
"diff"?: string | null
"prompt_kind": string
"offers_always": boolean
+ /** The model's reason for an `escalate` prompt (running a shell command outside the sandbox), shown beside the command; `None` otherwise. */
+ "justification"?: string | null
"type": "permission_request"
}
diff --git a/protocol/rpc-schema.json b/protocol/rpc-schema.json
index c630fba52..472a08071 100644
--- a/protocol/rpc-schema.json
+++ b/protocol/rpc-schema.json
@@ -1098,6 +1098,13 @@
"offers_always": {
"type": "boolean"
},
+ "justification": {
+ "description": "The model's reason for an `escalate` prompt (running a shell command\noutside the sandbox), shown beside the command; `None` otherwise.",
+ "type": [
+ "string",
+ "null"
+ ]
+ },
"type": {
"type": "string",
"const": "permission_request"
diff --git a/protocol/schema.json b/protocol/schema.json
index 09a38e149..0190660f1 100644
--- a/protocol/schema.json
+++ b/protocol/schema.json
@@ -656,6 +656,13 @@
"offers_always": {
"type": "boolean"
},
+ "justification": {
+ "description": "The model's reason for an `escalate` prompt (running a shell command\noutside the sandbox), shown beside the command; `None` otherwise.",
+ "type": [
+ "string",
+ "null"
+ ]
+ },
"type": {
"type": "string",
"const": "permission_request"
diff --git a/src-tauri/jan-cli/src/main.rs b/src-tauri/jan-cli/src/main.rs
index d54c81a82..171298a3a 100644
--- a/src-tauri/jan-cli/src/main.rs
+++ b/src-tauri/jan-cli/src/main.rs
@@ -101,6 +101,10 @@ struct SandboxArgs {
/// Run shell commands unconfined, overriding a persistent sandbox setting
#[arg(long, conflicts_with = "sandbox")]
no_sandbox: bool,
+ /// Let a sandboxed shell command that asks to escalate run outside the
+ /// sandbox without an escalation prompt (--safe still asks once)
+ #[arg(long)]
+ allow_escalation: bool,
}
/// Whether this invocation works in its own git worktree.
@@ -138,6 +142,12 @@ impl SandboxArgs {
_ => None,
}
}
+
+ /// `None` when not passed, so `[tools].allow_escalation` decides. There is
+ /// no `--no-allow-escalation`: off is already the default.
+ fn escalation_flag(self) -> Option<bool> {
+ self.allow_escalation.then_some(true)
+ }
}
/// Session-resume selection, shared by the bare TUI and `jan cli agent run`.
@@ -781,6 +791,7 @@ async fn main() {
auto_approve: !cli.safe,
plan: cli.plan,
sandbox: cli.sandbox.into_flag(),
+ allow_escalation: cli.sandbox.escalation_flag(),
worktree: cli.worktree.into_flag(),
..Default::default()
},
@@ -1099,6 +1110,7 @@ async fn run_agent(cmd: AgentCommands) -> Result<(), String> {
SessionFlags {
auto_approve: !safe,
sandbox: sandbox.into_flag(),
+ allow_escalation: sandbox.escalation_flag(),
worktree: worktree.into_flag(),
max_turns: budget.max_turns,
max_session_tokens: budget.max_session_tokens,
@@ -1129,6 +1141,7 @@ async fn run_agent(cmd: AgentCommands) -> Result<(), String> {
SessionFlags {
auto_approve: !safe,
sandbox: sandbox.into_flag(),
+ allow_escalation: sandbox.escalation_flag(),
..Default::default()
},
)
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/commands.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/commands.rs
index c92398cb9..eb3054ecd 100644
--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/commands.rs
+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/commands.rs
@@ -966,6 +966,15 @@ async fn execute_tool_inner(
}
.into());
}
+ // The chat sandbox is throwaway by design and never lifted: escalation
+ // is a CLI capability, so say so rather than "not available yet".
+ Decision::Prompt(PromptKind::Escalate) => {
+ return Err(format!(
+ "tool '{name}' cannot run outside the sandbox here; the command was not run. \
+ Run it without `escalate`."
+ )
+ .into());
+ }
Decision::Prompt(kind) => {
return Err(format!(
"tool '{name}' needs user approval ({kind:?}) and is not available yet"
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/gate.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/gate.rs
index 8d642fa01..7ad869e23 100644
--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/gate.rs
+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/gate.rs
@@ -20,6 +20,24 @@ pub enum PromptKind {
/// exists.
WriteEscape,
Exec,
+ /// A shell command asking to run outside the OS sandbox (`escalate: true`).
+ /// Never covered by a grant, an allow rule or auto-approval: it is the one
+ /// prompt that widens the sandbox itself, so it always needs a fresh
+ /// answer (see [`requests_escalation`]).
+ Escalate,
+}
+
+/// The `shell` argument that asks to run the command unconfined.
+pub const ESCALATE_ARG: &str = "escalate";
+/// The `shell` argument carrying the model's reason, shown in the prompt.
+pub const JUSTIFICATION_ARG: &str = "justification";
+
+/// Whether this call asks to leave the sandbox: the shell with `escalate`
+/// set to literal `true`. Any other tool, or any other value, is not a
+/// request, so a confused model cannot escalate by accident.
+pub fn requests_escalation(tool: &BuiltinTool, args: &serde_json::Value) -> bool {
+ tool.name == crate::tools::SHELL_TOOL
+ && args.get(ESCALATE_ARG).and_then(|v| v.as_bool()) == Some(true)
}
/// The user's answer to a permission prompt (wire shape for a later IPC command).
@@ -57,6 +75,7 @@ impl SessionGrants {
PromptKind::WriteEscape => self.write_escape,
// Exec coverage is command-specific; use `covers_command`.
PromptKind::Exec => false,
+ PromptKind::Escalate => false,
}
}
@@ -79,6 +98,8 @@ impl SessionGrants {
PromptKind::WriteEscape => self.write_escape = true,
// No-op: exec is granted per command via `grant_command`.
PromptKind::Exec => {}
+ // No-op: an escalation is answered once, never remembered.
+ PromptKind::Escalate => {}
}
}
@@ -179,6 +200,11 @@ pub fn resolve_decision(
return Decision::HardDeny(DenyReason::Hidden);
}
}
+ // After the hard denies, ahead of allow rules and grants: those vouch for
+ // the tool running confined, which is not what is being asked.
+ if requests_escalation(tool, args) {
+ return Decision::Prompt(PromptKind::Escalate);
+ }
if perms.is_allowed(tool.name) {
return Decision::Allow;
}
@@ -508,6 +534,97 @@ mod tests {
let _ = std::fs::remove_dir_all(&root);
}
+ fn escalation_ctx(root: &Path) -> GateContext<'_> {
+ GateContext {
+ project_root: root,
+ scratch: None,
+ read_roots: &[],
+ write_roots: &[],
+ hidden_root: None,
+ }
+ }
+
+ /// An escalation asks to leave the sandbox, which no allow rule, session
+ /// grant or earlier "allow always" was given for: it prompts regardless.
+ #[test]
+ fn escalated_shell_prompts_past_allow_rules_and_grants() {
+ let root = unique_root();
+ let args = json!({"command": "cargo build", "escalate": true, "justification": "fetch crates"});
+ let mut grants = SessionGrants::default();
+ grants.grant_command("cargo build");
+ for perms in [
+ ToolPermissions::allow_all(),
+ ToolPermissions::new(PermissionDefault::ReadOnly, &s(&["shell"]), &[], &[]),
+ ToolPermissions::default(),
+ ] {
+ let d = resolve_decision(
+ lookup("shell").unwrap(),
+ &args,
+ &escalation_ctx(&root),
+ &perms,
+ &grants,
+ );
+ assert_eq!(d, Decision::Prompt(PromptKind::Escalate));
+ }
+ // `grant` is a no-op for it, so nothing can make it stick.
+ grants.grant(PromptKind::Escalate);
+ assert!(!grants.covers(PromptKind::Escalate));
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
+ /// `escalate: false` (or absent) is an ordinary exec.
+ #[test]
+ fn unescalated_shell_is_ordinary_exec() {
+ let root = unique_root();
+ let perms = ToolPermissions::new(PermissionDefault::ReadOnly, &s(&["shell"]), &[], &[]);
+ let d = resolve_decision(
+ lookup("shell").unwrap(),
+ &json!({"command": "ls", "escalate": false}),
+ &escalation_ctx(&root),
+ &perms,
+ &SessionGrants::default(),
+ );
+ assert_eq!(d, Decision::Allow);
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
+ /// The two hard denies still win: a denied shell, and a command reaching
+ /// the Jan home, are refused before anyone is asked to unconfine them.
+ #[test]
+ fn hard_denies_win_over_escalation() {
+ let root = unique_root();
+ let jan = root.join(".jan");
+ std::fs::create_dir_all(&jan).unwrap();
+ let ctx = GateContext { hidden_root: Some(&jan), ..escalation_ctx(&root) };
+ let d = resolve_decision(
+ lookup("shell").unwrap(),
+ &json!({"command": "cat .jan/config.toml", "escalate": true}),
+ &ctx,
+ &ToolPermissions::allow_all(),
+ &SessionGrants::default(),
+ );
+ assert_eq!(d, Decision::HardDeny(DenyReason::Hidden));
+ let denied = ToolPermissions::new(PermissionDefault::Allow, &[], &s(&["shell"]), &[]);
+ let d = resolve_decision(
+ lookup("shell").unwrap(),
+ &json!({"command": "ls", "escalate": true}),
+ &escalation_ctx(&root),
+ &denied,
+ &SessionGrants::default(),
+ );
+ assert_eq!(d, Decision::HardDeny(DenyReason::Policy));
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
+ /// Only the shell can escalate: the flag on any other tool means nothing.
+ #[test]
+ fn escalation_is_shell_only() {
+ assert!(requests_escalation(lookup("shell").unwrap(), &json!({"command": "x", "escalate": true})));
+ assert!(!requests_escalation(lookup("shell").unwrap(), &json!({"command": "x"})));
+ assert!(!requests_escalation(lookup("shell").unwrap(), &json!({"command": "x", "escalate": "yes"})));
+ assert!(!requests_escalation(lookup("write").unwrap(), &json!({"path": "x", "escalate": true})));
+ }
+
#[test]
fn mcp_grant_is_scoped_to_tool_name() {
let mut grants = SessionGrants::default();
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/handlers.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/handlers.rs
index a689202f1..033635110 100644
--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/handlers.rs
+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/handlers.rs
@@ -926,15 +926,12 @@ async fn bash(args: &serde_json::Value, ctx: &ToolContext<'_>) -> String {
// collecting output after this call has already returned.
let sink = ctx.on_output.clone();
let sandboxed = ctx.sandbox;
+ let escalation = ctx.escalation;
tokio::spawn(async move {
let mut out = collect_and_format(child, spill_scratch, sink).await;
// Appended inside the task so a backgrounded job carries the hint too.
- // `Permission denied` on its own tells the model nothing about *why*;
- // without this it retries the same command until it gives up. Only when
- // confined: unsandboxed, a denial is an ordinary filesystem permission
- // and the hint would name limits that are not in force.
- if sandboxed && bash_result_failed(&out) && jail::looks_denied(&out) {
- out.push_str(&jail::denial_hint(&policy));
+ if sandboxed {
+ out.push_str(&sandbox_denial_note(&out, &policy, escalation));
}
if let Some(pid) = pid {
proc::unregister(thread_owned.as_deref(), pid);
@@ -1266,6 +1263,27 @@ pub fn tool_result_failed(tool: &BuiltinTool, content: &str) -> bool {
|| (tool.capability == super::Capability::Exec && bash_result_failed(content))
}
+/// What a confined command's output gets appended when it failed on the
+/// sandbox, empty otherwise. `Permission denied` on its own tells the model
+/// nothing about *why*; without this it retries the same command until it
+/// gives up. Only for a confined run: unsandboxed, a denial is an ordinary
+/// filesystem permission and the note would name limits that are not in force.
+/// With `escalation` the note also names the way out, so the model reaches for
+/// it exactly when it applies rather than from the tool description alone.
+fn sandbox_denial_note(out: &str, policy: &jail::Policy, escalation: bool) -> String {
+ if !(bash_result_failed(out) && jail::looks_denied(out)) {
+ return String::new();
+ }
+ let mut note = jail::denial_hint(policy);
+ if escalation {
+ note.push_str(ESCALATION_HINT);
+ }
+ note
+}
+
+/// The escalation half of [`sandbox_denial_note`].
+const ESCALATION_HINT: &str = "\n[If this command is needed for the task, rerun it with `escalate: true` and a `justification` to ask the user to run it outside the sandbox.]";
+
/// True when a shell tool result reports failure via its exit marker: a
/// non-zero `[exit N]` or a signal termination. The marker is emitted by
/// [`BashCapture::finish`] on its own line and a truncation note may follow it,
@@ -3232,6 +3250,22 @@ mod tests {
let _ = std::fs::remove_dir_all(&root);
}
+ /// A sandbox denial names the way out only when the run offers it, and an
+ /// ordinary failure (or a success) gets no note at all.
+ #[test]
+ fn sandbox_denial_note_mentions_escalation_only_when_offered() {
+ let policy = jail::Policy::new(Path::new("/w"), true);
+ let denied = "touch: cannot touch '/x': Read-only file system\n[exit 1]";
+ let plain = sandbox_denial_note(denied, &policy, false);
+ assert!(plain.contains("[sandbox:"), "got: {plain}");
+ assert!(!plain.contains("escalate"));
+ let offered = sandbox_denial_note(denied, &policy, true);
+ assert!(offered.starts_with(&plain));
+ assert!(offered.contains("escalate: true"));
+ assert!(sandbox_denial_note("no such file\n[exit 1]", &policy, true).is_empty());
+ assert!(sandbox_denial_note("Read-only file system\n[exit 0]", &policy, true).is_empty());
+ }
+
#[test]
fn bash_result_failed_detects_nonzero_and_signal_markers() {
assert!(bash_result_failed("output\n[exit 1]"));
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/mod.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/mod.rs
index a102f08ef..f5881b091 100644
--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/mod.rs
+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/mod.rs
@@ -135,6 +135,12 @@ pub struct ToolContext<'a> {
/// gate is then the only thing between the model and the machine, which is
/// why nothing else about the gate changes when this is off.
pub sandbox: bool,
+ /// Whether this run offers `shell` escalation (see
+ /// [`gate::requests_escalation`]). Only tells a sandbox denial to mention
+ /// it: the handler never reads `escalate` itself, so a call reaches the
+ /// unconfined shell only through a caller that got the user's approval and
+ /// cleared [`Self::sandbox`] for it.
+ pub escalation: bool,
/// Where a tool sends output as it is produced, when the caller wants to
/// show it live. `None` means "collect and return only", which is what every
/// non-interactive caller wants.
@@ -222,6 +228,7 @@ impl std::fmt::Debug for ToolContext<'_> {
.field("home_readonly", &self.home_readonly)
.field("scratch_root", &self.scratch_root)
.field("sandbox", &self.sandbox)
+ .field("escalation", &self.escalation)
.field("on_output", &self.on_output.is_some())
.field("read_roots", &self.read_roots)
.field("write_roots", &self.write_roots)
@@ -375,6 +382,7 @@ impl<'a> ToolContext<'a> {
home_readonly: false,
scratch_root: None,
sandbox: true,
+ escalation: false,
on_output: None,
read_roots: &[],
write_roots: &[],
@@ -556,6 +564,12 @@ impl<'a> ToolContext<'a> {
self
}
+ /// Mention escalation in sandbox denials. See [`Self::escalation`].
+ pub fn with_escalation(mut self, escalation: bool) -> Self {
+ self.escalation = escalation;
+ self
+ }
+
/// Run `bash` under OS confinement (the default). See [`Self::sandbox`].
///
/// Turning it off also drops the scratch: the scratch only makes sense as
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/schema.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/schema.rs
index 1a3617186..6685dabe4 100644
--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/schema.rs
+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/schema.rs
@@ -23,6 +23,34 @@ pub fn bash_description(kind: super::proc::ShellKind) -> String {
}
}
+/// Appended to the shell description when the run offers escalation.
+const ESCALATE_NOTE: &str = " Commands run inside an OS sandbox. If a command that matters to the task fails because of the sandbox (a read-only file system or permission error outside the project, such as a package manager writing its cache, or a blocked download), rerun the same command with `escalate: true` and a one-line `justification`: the user is asked to approve running it outside the sandbox. Never escalate pre-emptively, and never to work around a denial the user gave.";
+
+/// Add the escalation arguments to the `shell` schema in `schemas`, for a run
+/// whose shell is sandboxed and whose user can be asked to lift it. Applied
+/// once per run by the caller, so the array stays byte-identical across turns;
+/// a run without escalation keeps the plain schema.
+pub fn offer_escalation(schemas: &mut [Value]) {
+ for schema in schemas.iter_mut() {
+ let function = &mut schema["function"];
+ if function["name"] != super::SHELL_TOOL {
+ continue;
+ }
+ if let Some(description) = function["description"].as_str() {
+ function["description"] = Value::String(format!("{description}{ESCALATE_NOTE}"));
+ }
+ let properties = &mut function["parameters"]["properties"];
+ properties[super::gate::ESCALATE_ARG] = json!({
+ "type": "boolean",
+ "description": "Ask the user to run this command outside the sandbox. Only after it failed inside it."
+ });
+ properties[super::gate::JUSTIFICATION_ARG] = json!({
+ "type": "string",
+ "description": "Required with escalate: why the command needs to leave the sandbox, shown to the user."
+ });
+ }
+}
+
/// OpenAI function schemas for the built-in tools, one per `BUILTIN_TOOLS`
/// entry. `screenshot` is desktop-only (`feature = "tauri"`), so the headless
/// CLI advertises one fewer.
@@ -300,6 +328,28 @@ mod tests {
use super::*;
use crate::tools::BUILTIN_TOOLS;
+ /// The plain array never mentions escalation; offering it touches only the
+ /// shell entry, adding both arguments and the when-to-use note.
+ #[test]
+ fn escalation_is_offered_only_on_request_and_only_on_the_shell() {
+ let plain = builtin_tool_schemas();
+ assert!(!serde_json::to_string(&plain).unwrap().contains("escalate"));
+ let mut offered = plain.clone();
+ offer_escalation(&mut offered);
+ for (before, after) in plain.iter().zip(&offered) {
+ if before["function"]["name"] == crate::tools::SHELL_TOOL {
+ let props = &after["function"]["parameters"]["properties"];
+ assert_eq!(props["escalate"]["type"], "boolean");
+ assert_eq!(props["justification"]["type"], "string");
+ assert!(after["function"]["description"].as_str().unwrap().contains("escalate: true"));
+ // Still optional: an ordinary call needs only `command`.
+ assert_eq!(after["function"]["parameters"]["required"], json!(["command"]));
+ } else {
+ assert_eq!(before, after);
+ }
+ }
+ }
+
/// ls/find/grep stay in BUILTIN_TOOLS (recognized + executable) but are not
/// advertised -- bash covers listing and searching -- so the offered set is
/// BUILTIN_TOOLS minus that trio. Every other builtin must be advertised, in
diff --git a/src-tauri/src/core/agent/events.rs b/src-tauri/src/core/agent/events.rs
index 951bbc747..1a171a4b1 100644
--- a/src-tauri/src/core/agent/events.rs
+++ b/src-tauri/src/core/agent/events.rs
@@ -285,6 +285,10 @@ pub enum StreamEvent {
diff: Option<String>,
prompt_kind: String,
offers_always: bool,
+ /// The model's reason for an `escalate` prompt (running a shell command
+ /// outside the sandbox), shown beside the command; `None` otherwise.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ justification: Option<String>,
},
/// A host-registered tool was called and the run is waiting for the host to
/// execute it. The client replies with a `tool_result` line carrying this
@@ -750,6 +754,7 @@ pub(crate) mod tests {
diff: None,
prompt_kind: "exec".into(),
offers_always: true,
+ justification: None,
},
),
(
@@ -999,6 +1004,7 @@ pub(crate) mod tests {
diff: Some("@@ created file @@\n+ hi".into()),
prompt_kind: "write".into(),
offers_always: true,
+ justification: None,
})
.unwrap();
assert_eq!(
diff --git a/src-tauri/src/core/agent/loop.rs b/src-tauri/src/core/agent/loop.rs
index a4ba4d342..82535c149 100644
--- a/src-tauri/src/core/agent/loop.rs
+++ b/src-tauri/src/core/agent/loop.rs
@@ -164,6 +164,11 @@ pub(crate) struct OrchestrationArgs {
/// by dispatched subagents via the cloned parent args, so a child shell is
/// confined exactly as its parent's was.
pub sandbox: Option<bool>,
+ /// Per-invocation `--allow-escalation`: let a sandboxed `shell` call that
+ /// asks to escalate run unconfined without a prompt. `None` falls through
+ /// to `[tools].allow_escalation`, then off. Inherited by subagents like
+ /// `sandbox`, so a child can escalate exactly when its parent could.
+ pub allow_escalation: Option<bool>,
/// A monitor set owned by the session rather than by this run. When set,
/// a running monitor does not park the run: the model's turn ends and the
/// owner starts a new turn when a match lands. `None` (a headless run, a
@@ -696,6 +701,8 @@ struct CompositeToolInvoker {
/// Whether `bash` is confined at all. Resolved once per run by
/// [`resolve_sandbox`]; always true on the desktop.
sandbox: bool,
+ /// How a `shell` call asking to escalate is answered; see [`Escalation`].
+ escalation: Escalation,
/// The Jan home, refused to the general tools and masked from the shell
/// while sandboxed (`project::hidden_root`). Kept beside `sandbox` and set
/// with it, so the two cannot disagree.
@@ -863,6 +870,40 @@ fn ask_timeout_setting() -> Option<std::time::Duration> {
None
}
+/// How this run answers a `shell` call that asks to run outside the sandbox.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+enum Escalation {
+ /// Not offered: the shell is unconfined already, or the surface (the
+ /// desktop's throwaway chat sandbox) never lifts it. A call that asks
+ /// anyway is refused.
+ Off,
+ /// Offered, and each request waits for a human answer. Auto-approval does
+ /// not cover it, and a headless run with no terminal denies it.
+ Prompt,
+ /// Offered and granted without an escalation prompt (`--allow-escalation`
+ /// or `[tools].allow_escalation`), for unattended runs that accept the
+ /// risk. The exec approval underneath still applies: a command this run
+ /// would have asked about confined (`--safe`) is asked about once.
+ Allow,
+}
+
+impl Escalation {
+ fn offered(self) -> bool {
+ self != Escalation::Off
+ }
+}
+
+/// Escalation is a CLI capability of a sandboxed shell: there is nothing to
+/// escalate out of when the shell is unconfined, and the desktop's chat
+/// sandbox is throwaway by design, so it is never lifted there.
+fn resolve_escalation(sandbox: bool, allow: bool) -> Escalation {
+ match (cfg!(feature = "cli") && sandbox, allow) {
+ (false, _) => Escalation::Off,
+ (true, false) => Escalation::Prompt,
+ (true, true) => Escalation::Allow,
+ }
+}
+
/// Whether `bash` would be confined in `project_root` with no `--sandbox` flag
/// passed: the answer `jan cli agent status` reports and the TUI notices on.
pub fn effective_sandbox(project_root: &std::path::Path) -> bool {
@@ -879,6 +920,7 @@ struct ResolvedSettings {
allow_network: bool,
allow_home_read: bool,
sandbox: bool,
+ escalation: Escalation,
env_passthrough: Vec<String>,
env_set: Vec<(String, String)>,
/// `[prompt]`: where each system-prompt composer may sit. Resolved with the
@@ -894,13 +936,19 @@ struct ResolvedSettings {
fn resolve_run_settings(
project_root: &std::path::Path,
sandbox_flag: Option<bool>,
+ escalation_flag: Option<bool>,
) -> ResolvedSettings {
let settings = crate::core::agent::project::run_settings(project_root);
+ let sandbox = resolve_sandbox(sandbox_flag, settings.sandbox);
ResolvedSettings {
enabled_skills: settings.enabled_skills,
allow_network: resolve_allow_network(settings.allow_network),
allow_home_read: resolve_allow_home_read(settings.allow_home_read),
- sandbox: resolve_sandbox(sandbox_flag, settings.sandbox),
+ sandbox,
+ escalation: resolve_escalation(
+ sandbox,
+ escalation_flag.or(settings.allow_escalation).unwrap_or(false),
+ ),
env_passthrough: resolve_env_passthrough(settings.env_passthrough),
env_set: resolve_env_set(settings.env_set),
prompt: settings.prompt,
@@ -1099,6 +1147,7 @@ impl CompositeToolInvoker {
ctx.with_network(self.allow_network)
.with_home_readonly(self.allow_home_read)
.with_sandbox(self.sandbox)
+ .with_escalation(self.escalation.offered())
.with_hidden_root(self.hidden_root.as_deref())
.with_scratch_root(&self.scratch_root)
.with_env_passthrough(&self.env_passthrough)
@@ -1170,6 +1219,76 @@ impl CompositeToolInvoker {
.with_output_sink(output_sink(&self.events, id))
}
+ /// Whether this run would have approved `args` as a plain, confined exec
+ /// without asking: auto-approval, a `[tools]` allow rule naming the shell,
+ /// or a session grant covering every command it runs.
+ fn exec_preapproved(&self, name: &str, args: &serde_json::Value) -> bool {
+ let command = args.get("command").and_then(|v| v.as_str()).unwrap_or("");
+ self.auto_approve
+ || self.permissions.is_allowed(name)
+ || self.grants.lock().unwrap().covers_command(command)
+ }
+
+ /// Answer a `shell` call that asks to run outside the sandbox, and run it
+ /// unconfined when allowed. Only a fresh human answer, or the explicit
+ /// opt-in on a command the run would have run confined without asking,
+ /// lets it through: auto-approval or a session grant alone never does, and
+ /// "allow always" is not offered. The gate has already refused the hard
+ /// denies (the Jan home, a denied shell) before this is reached.
+ async fn escalate(
+ &self,
+ name: &str,
+ tool: &tauri_plugin_agent_tools::tools::BuiltinTool,
+ args: &serde_json::Value,
+ id: &str,
+ ) -> String {
+ let approved = match self.escalation {
+ Escalation::Off => return escalation_unavailable_msg(name, self.sandbox),
+ Escalation::Allow if self.exec_preapproved(name, args) => true,
+ // The opt-in drops the escalation prompt, not the exec approval
+ // under it: under `--safe` the command would have been asked about
+ // anyway, so one prompt covers both.
+ Escalation::Allow | Escalation::Prompt => {
+ let request_id = next_permission_id();
+ let (tx, rx) = tokio::sync::oneshot::channel();
+ self.permission_requests
+ .lock()
+ .await
+ .insert(request_id.clone(), tx);
+ let _ = self.events.send(StreamEvent::PermissionRequest {
+ request_id: request_id.clone(),
+ tool_name: name.to_string(),
+ capability: "exec outside the sandbox".to_string(),
+ path: None,
+ command: args.get("command").and_then(|v| v.as_str()).map(String::from),
+ diff: None,
+ prompt_kind: "escalate".to_string(),
+ offers_always: false,
+ justification: args
+ .get(tauri_plugin_agent_tools::tools::gate::JUSTIFICATION_ARG)
+ .and_then(|v| v.as_str())
+ .map(str::trim)
+ .filter(|j| !j.is_empty())
+ .map(String::from),
+ });
+ // No timeout, like every other prompt: cancelling the run
+ // drops the sender, which reads as Deny.
+ let decision = rx.await.unwrap_or(PermissionDecision::Deny);
+ self.permission_requests.lock().await.remove(&request_id);
+ // `AllowAlways` is not offered; a client that sends it anyway
+ // gets this one call, never a lasting grant.
+ decision != PermissionDecision::Deny
+ }
+ };
+ if !approved {
+ return escalation_denied_msg(name);
+ }
+ let ctx = self.streaming_tool_context(id).with_sandbox(false);
+ tauri_plugin_agent_tools::tools::handlers::execute_builtin_with_diff(tool, args, &ctx)
+ .await
+ .0
+ }
+
/// Fire the hooks for `event` and fold their answers into the run: a
/// `context` answer and every failure notice become `<SYSTEM>` reminders
/// queued alongside the monitor's, and the deny (if any) is returned for
@@ -1391,6 +1510,7 @@ impl CompositeToolInvoker {
diff: None,
prompt_kind: "mcp".to_string(),
offers_always: true,
+ justification: None,
});
let decision = rx.await.unwrap_or(PermissionDecision::Deny);
self.permission_requests.lock().await.remove(&request_id);
@@ -1415,6 +1535,7 @@ impl CompositeToolInvoker {
diff: None,
prompt_kind: "subagent_create".to_string(),
offers_always: false,
+ justification: None,
});
let decision = rx.await.unwrap_or(PermissionDecision::Deny);
self.permission_requests.lock().await.remove(&request_id);
@@ -1578,6 +1699,7 @@ impl CompositeToolInvoker {
diff: None,
prompt_kind: "monitor".to_string(),
offers_always: false,
+ justification: None,
});
let decision = rx.await.unwrap_or(PermissionDecision::Deny);
self.permission_requests.lock().await.remove(&request_id);
@@ -1841,6 +1963,32 @@ fn hook_denied_msg(name: &str, reason: &str) -> String {
format!("ERROR: tool '{name}' {HOOK_DENIED}{reason}")
}
+/// A refused escalation. The command did not run at all, inside or outside the
+/// sandbox, and the model is told so along with the way a user enables it --
+/// a non-interactive run lands here too, where nobody could have approved.
+fn escalation_denied_msg(name: &str) -> String {
+ format!(
+ "ERROR: tool '{name}' escalation {DENIED_BY_USER}: the command was not run. Do not \
+ retry it outside the sandbox. If no one could answer (a non-interactive run), the \
+ user can allow escalation with --allow-escalation or [tools].allow_escalation."
+ )
+}
+
+/// An escalation request where escalation is not offered at all.
+fn escalation_unavailable_msg(name: &str, sandboxed: bool) -> String {
+ if sandboxed {
+ format!(
+ "ERROR: tool '{name}' cannot run outside the sandbox here; the command was not run. \
+ Run it without `escalate`, inside the sandbox."
+ )
+ } else {
+ format!(
+ "ERROR: tool '{name}' got `escalate`, but the shell is not sandboxed; the command \
+ was not run. Run it again without `escalate`."
+ )
+ }
+}
+
fn plan_mode_read_only_msg(name: &str) -> String {
format!("ERROR: tool '{name}' {PLAN_MODE_UNAVAILABLE} (plan mode is read-only)")
}
@@ -2341,6 +2489,14 @@ impl ToolInvoker for CompositeToolInvoker {
&self.permissions,
&snapshot,
);
+ // Escalation is settled here, before auto-approval can touch it:
+ // approving every prompt is a statement about tools running inside
+ // the sandbox, and this one asks to leave it.
+ if decision == Decision::Prompt(PromptKind::Escalate) {
+ let text = self.escalate(name, tool, &args, &id).await;
+ out.push(ToolOutcome::plain(id, text));
+ continue;
+ }
// Auto-approval suppresses every prompt (sandbox escape, write, exec) but
// still honors HardDeny, so explicit agent.toml denies hold.
let decision = match decision {
@@ -2423,6 +2579,8 @@ impl ToolInvoker for CompositeToolInvoker {
PromptKind::Write => "write",
PromptKind::WriteEscape => "write_escape",
PromptKind::Exec => "exec",
+ // Settled by `escalate` above; labelled for completeness.
+ PromptKind::Escalate => "escalate",
};
let path = tool
.path_args
@@ -2444,6 +2602,7 @@ impl ToolInvoker for CompositeToolInvoker {
diff,
prompt_kind: prompt_kind.to_string(),
offers_always: true,
+ justification: None,
});
// Sender dropped (client gone / run cancelled) => Deny. No timeout:
// the run is cancellable via agent_cancel, which drops this future.
@@ -2598,6 +2757,7 @@ pub(crate) async fn run_server_side_openai_orchestration(
// The top-level run is not a child: no dispatch gave it an id.
run_id: None,
sandbox: None,
+ allow_escalation: None,
monitors: None,
// Run-owned: the proxy has no conversation to deliver a later ping
// into, so background work must be settled before the run returns.
@@ -3061,7 +3221,7 @@ pub(crate) fn context_system_prompt_preview(
sandbox_flag: Option<bool>,
session_start: Option<&crate::core::agent::context::SessionStart>,
) -> Option<String> {
- let settings = resolve_run_settings(project_root, sandbox_flag);
+ let settings = resolve_run_settings(project_root, sandbox_flag, None);
let policy = crate::core::agent::project::prompt_policy(project_root);
build_run_system_prompt(
None,
@@ -3253,6 +3413,7 @@ async fn orchestrate_inner(
bg_shells: session_bg_shells,
subagent_bg: session_subagent_bg,
sandbox,
+ allow_escalation,
compaction,
session_start,
} = args;
@@ -3289,7 +3450,7 @@ async fn orchestrate_inner(
// nothing binds.
let settings = project_root
.as_deref()
- .map(|root| resolve_run_settings(root, *sandbox));
+ .map(|root| resolve_run_settings(root, *sandbox, *allow_escalation));
// The stable system prompt: identity, guidelines, environment, skills and
// the memory catalog. Byte-identical across the turns of a session, so it
@@ -3498,6 +3659,10 @@ async fn orchestrate_inner(
#[cfg(feature = "cli")]
host_tools,
);
+ // Resolved once per run, so the array is byte-identical across its turns.
+ if settings.as_ref().is_some_and(|s| s.escalation.offered()) {
+ tauri_plugin_agent_tools::tools::schema::offer_escalation(&mut openai_tools);
+ }
let (upstream_url, session_api_keys) = resolve_upstream_for_model(
&model_id,
@@ -3615,6 +3780,7 @@ async fn orchestrate_inner(
allow_network: settings.allow_network,
allow_home_read: settings.allow_home_read,
sandbox: settings.sandbox,
+ escalation: settings.escalation,
hidden_root: crate::core::agent::project::hidden_root(settings.sandbox),
scratch_root: scratch_root.clone(),
env_passthrough: settings.env_passthrough,
@@ -5799,7 +5965,7 @@ mod tests {
// ...and the run's resolved settings carry the same policy, which is
// what `orchestrate_inner` composes with.
assert_eq!(
- resolve_run_settings(&root, None)
+ resolve_run_settings(&root, None, None)
.prompt
.prefix_allow()
.map(<[String]>::len),
@@ -8453,6 +8619,7 @@ mod tests {
) -> CompositeToolInvoker {
CompositeToolInvoker {
sandbox: true,
+ escalation: Escalation::Off,
hidden_root: crate::core::agent::project::hidden_root(true),
mcp: McpToolInvoker {
tool_to_server: HashMap::new(),
@@ -9670,19 +9837,19 @@ mod tests {
};
write("[tools]\nallow_network = false\n[skills]\nenabled = [\"deploy\"]\n");
- let denied = resolve_run_settings(&root, None);
+ let denied = resolve_run_settings(&root, None, None);
assert!(!denied.allow_network, "explicit false must be honoured");
assert_eq!(denied.enabled_skills, vec!["deploy".to_string()]);
write("[tools]\nallow_network = true\n");
assert!(
- resolve_run_settings(&root, None).allow_network,
+ resolve_run_settings(&root, None, None).allow_network,
"explicit true must be honoured"
);
write("[tools]\ndefault = \"read-only\"\n");
assert_eq!(
- resolve_run_settings(&root, None).allow_network,
+ resolve_run_settings(&root, None, None).allow_network,
DEFAULT_ALLOW_NETWORK,
"unset must fall back to the surface default"
);
@@ -10838,6 +11005,185 @@ mod tests {
let _ = std::fs::remove_dir_all(&root);
}
+ /// A `shell` call asking to escalate, writing `marker` -- a path outside
+ /// the project, which only an unconfined shell can create on the host.
+ fn escalated_shell_call(marker: &std::path::Path) -> serde_json::Value {
+ let args = json!({
+ "command": format!("touch '{}'", marker.display()),
+ "escalate": true,
+ "justification": " write outside the project ",
+ });
+ json!({
+ "id": "esc",
+ "type": "function",
+ "function": { "name": "shell", "arguments": args.to_string() }
+ })
+ }
+
+ fn escalation_marker(root: &std::path::Path) -> std::path::PathBuf {
+ let marker = root.with_extension("escalated");
+ let _ = std::fs::remove_file(&marker);
+ marker
+ }
+
+ /// Auto-approval covers everything that runs inside the sandbox, never a
+ /// request to leave it: the prompt still goes out, without "allow always"
+ /// and with the model's reason, and an approved command runs unconfined.
+ #[tokio::test]
+ #[cfg(feature = "cli")]
+ async fn escalation_prompts_even_under_auto_approve_and_runs_unconfined() {
+ let root = unique_project_root();
+ let marker = escalation_marker(&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.clone());
+ invoker.auto_approve = true;
+ invoker.escalation = Escalation::Prompt;
+ let responder = tokio::spawn(async move {
+ loop {
+ match rx.recv().await {
+ Some(StreamEvent::PermissionRequest {
+ request_id,
+ prompt_kind,
+ offers_always,
+ justification,
+ command,
+ ..
+ }) => {
+ if let Some(tx) = registry.lock().await.remove(&request_id) {
+ let _ = tx.send(PermissionDecision::AllowOnce);
+ }
+ return (prompt_kind, offers_always, justification, command);
+ }
+ Some(_) => continue,
+ None => panic!("no prompt was sent"),
+ }
+ }
+ });
+ let out = invoker.invoke(&[escalated_shell_call(&marker)]).await.unwrap();
+ let (kind, always, justification, command) = responder.await.unwrap();
+ assert_eq!(kind, "escalate");
+ assert!(!always, "an escalation is never remembered");
+ assert_eq!(justification.as_deref(), Some("write outside the project"));
+ assert!(command.unwrap().starts_with("touch "));
+ assert!(out[0].content.contains("[exit 0]"), "{}", out[0].content);
+ assert!(marker.exists(), "the approved command ran on the host");
+ let _ = std::fs::remove_file(&marker);
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
+ /// A denied escalation runs nothing, inside the sandbox or out, and tells
+ /// the model not to retry it -- the same answer a headless run without a
+ /// terminal gets, which is why it names the opt-in.
+ #[tokio::test]
+ #[cfg(feature = "cli")]
+ async fn denied_escalation_runs_nothing() {
+ let root = unique_project_root();
+ let marker = escalation_marker(&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.clone());
+ invoker.escalation = Escalation::Prompt;
+ let responder = tokio::spawn(async move {
+ respond_once(&mut rx, &registry, PermissionDecision::Deny).await;
+ });
+ let out = invoker.invoke(&[escalated_shell_call(&marker)]).await.unwrap();
+ responder.await.unwrap();
+ assert!(out[0].content.contains("denied by user"), "{}", out[0].content);
+ assert!(out[0].content.contains("--allow-escalation"));
+ assert!(!marker.exists());
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
+ /// The explicit opt-in runs an escalation without asking anyone.
+ #[tokio::test]
+ #[cfg(feature = "cli")]
+ async fn allowed_escalation_runs_without_a_prompt() {
+ let root = unique_project_root();
+ let marker = escalation_marker(&root);
+ let (tx, mut rx) = mpsc::unbounded_channel();
+ let mut invoker = build_prompting_invoker(root.clone(), tx, PermissionRegistry::default());
+ invoker.escalation = Escalation::Allow;
+ invoker.auto_approve = true;
+ let out = invoker.invoke(&[escalated_shell_call(&marker)]).await.unwrap();
+ assert!(out[0].content.contains("[exit 0]"), "{}", out[0].content);
+ assert!(marker.exists());
+ while let Ok(ev) = rx.try_recv() {
+ assert!(!matches!(ev, StreamEvent::PermissionRequest { .. }), "prompted");
+ }
+ let _ = std::fs::remove_file(&marker);
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
+ /// The opt-in drops only the escalation prompt, never the exec approval
+ /// underneath it: under `--safe`, adding `escalate: true` must not turn a
+ /// command that would have been asked about into one that runs unasked.
+ /// The user is asked once, and a Deny runs nothing.
+ #[tokio::test]
+ #[cfg(feature = "cli")]
+ async fn allowed_escalation_still_asks_under_safe() {
+ let root = unique_project_root();
+ let marker = escalation_marker(&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.clone());
+ invoker.escalation = Escalation::Allow;
+ let responder = tokio::spawn(async move {
+ let mut kinds = Vec::new();
+ while let Some(ev) = rx.recv().await {
+ if let StreamEvent::PermissionRequest { request_id, prompt_kind, .. } = ev {
+ kinds.push(prompt_kind);
+ if let Some(tx) = registry.lock().await.remove(&request_id) {
+ let _ = tx.send(PermissionDecision::Deny);
+ }
+ }
+ }
+ kinds
+ });
+ let out = invoker.invoke(&[escalated_shell_call(&marker)]).await.unwrap();
+ drop(invoker);
+ assert_eq!(responder.await.unwrap(), ["escalate"], "asked exactly once");
+ assert!(out[0].content.contains("denied by user"), "{}", out[0].content);
+ assert!(!marker.exists(), "--safe was bypassed");
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
+ /// Where escalation is not offered (the desktop, an unconfined shell) a
+ /// request for it is refused without running or prompting, even under
+ /// auto-approval.
+ #[tokio::test]
+ async fn escalation_is_refused_where_it_is_not_offered() {
+ let root = unique_project_root();
+ let marker = escalation_marker(&root);
+ let (tx, mut rx) = mpsc::unbounded_channel();
+ let mut invoker = build_prompting_invoker(root.clone(), tx, PermissionRegistry::default());
+ invoker.auto_approve = true;
+ let out = invoker.invoke(&[escalated_shell_call(&marker)]).await.unwrap();
+ assert!(out[0].content.starts_with("ERROR"), "{}", out[0].content);
+ assert!(out[0].content.contains("was not run"));
+ assert!(!marker.exists());
+ while let Ok(ev) = rx.try_recv() {
+ assert!(!matches!(ev, StreamEvent::PermissionRequest { .. }), "prompted");
+ }
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
+ /// Escalation exists only for a sandboxed CLI shell, and the opt-in only
+ /// skips the prompt.
+ #[test]
+ fn escalation_resolves_from_sandbox_and_opt_in() {
+ #[cfg(feature = "cli")]
+ {
+ assert_eq!(resolve_escalation(false, true), Escalation::Off);
+ assert_eq!(resolve_escalation(true, false), Escalation::Prompt);
+ assert_eq!(resolve_escalation(true, true), Escalation::Allow);
+ }
+ #[cfg(not(feature = "cli"))]
+ for (sandbox, allow) in [(true, true), (true, false), (false, true)] {
+ assert_eq!(resolve_escalation(sandbox, allow), Escalation::Off);
+ }
+ }
+
#[tokio::test]
async fn auto_approve_writes_without_prompting() {
let root = unique_project_root();
diff --git a/src-tauri/src/core/agent/otel/tests.rs b/src-tauri/src/core/agent/otel/tests.rs
index 153b04618..48893eca2 100644
--- a/src-tauri/src/core/agent/otel/tests.rs
+++ b/src-tauri/src/core/agent/otel/tests.rs
@@ -219,6 +219,7 @@ fn tool_decisions_name_their_source() {
diff: None,
prompt_kind: "exec".into(),
offers_always: true,
+ justification: None,
},
result("b", "ERROR: tool 'bash' denied by user"),
call("c", "write"),
diff --git a/src-tauri/src/core/agent/project.rs b/src-tauri/src/core/agent/project.rs
index af1d85b96..538a2426b 100644
--- a/src-tauri/src/core/agent/project.rs
+++ b/src-tauri/src/core/agent/project.rs
@@ -302,6 +302,13 @@ pub(crate) struct ToolsSection {
/// checks it out.
#[serde(default)]
pub sandbox: Option<bool>,
+ /// Let a sandboxed `shell` call that asks to escalate run unconfined
+ /// without an escalation prompt; an exec approval the run requires anyway
+ /// (`--safe`) still applies. `None` (unset) and `false` keep escalation
+ /// behind a human answer -- auto-approval never covers it -- and refuse it
+ /// where nobody can answer. For unattended runs that accept the risk.
+ #[serde(default)]
+ pub allow_escalation: Option<bool>,
/// Host env-var names (exact or `*`-glob) the sandboxed `bash` may inherit
/// beyond the fixed base allowlist, merged over `~/.jan/config.toml`. Empty
/// by default; a secret-looking name is never copied by a glob.
@@ -372,6 +379,11 @@ allow_write = []
# ~/.jan/config.toml; the desktop always confines. Set it here to require
# confinement for anyone working in this project.
# sandbox = true
+# Let a sandboxed shell command that asks to escalate run outside the sandbox
+# without asking you. Off by default: escalation always waits for your answer
+# (even when other tools are auto-approved) and is refused where nobody can
+# answer, such as a piped headless run. Same as passing --allow-escalation.
+# allow_escalation = true
# Host environment variables the shell may inherit beyond the minimal base
# (PATH, HOME, TMPDIR, ...). Names are exact or use a "*" wildcard; merged with
# ~/.jan/config.toml. A secret-looking name (*KEY*, *TOKEN*, ...) is never
@@ -521,6 +533,8 @@ pub(crate) struct RunSettings {
/// `[tools].sandbox`; `None` when unset, so the caller applies the default
/// appropriate to its surface.
pub sandbox: Option<bool>,
+ /// `[tools].allow_escalation`; `None` when unset.
+ pub allow_escalation: Option<bool>,
/// `[tools].env_passthrough`: host env-var names/globs the shell may inherit
/// beyond the base allowlist. Merged with the global setting by the caller.
pub env_passthrough: Vec<String>,
@@ -553,6 +567,7 @@ pub(crate) fn run_settings(project_root: &Path) -> RunSettings {
allow_network: cfg.tools.allow_network,
allow_home_read: cfg.tools.allow_home_read,
sandbox: cfg.tools.sandbox,
+ allow_escalation: cfg.tools.allow_escalation,
env_passthrough: cfg.tools.env_passthrough,
env_set: cfg.tools.env_set.into_iter().collect(),
tool_notices,
diff --git a/src-tauri/src/core/agent/subagent.rs b/src-tauri/src/core/agent/subagent.rs
index c078d71e8..e0ce1122c 100644
--- a/src-tauri/src/core/agent/subagent.rs
+++ b/src-tauri/src/core/agent/subagent.rs
@@ -4362,6 +4362,7 @@ pub(crate) mod tests {
run_mode: crate::core::agent::plan::RunMode::Normal,
session_id: None,
sandbox: None,
+ allow_escalation: None,
compaction: None,
session_start: None,
}
diff --git a/src-tauri/src/core/cli/acp.rs b/src-tauri/src/core/cli/acp.rs
index f708a6e33..6061d236e 100644
--- a/src-tauri/src/core/cli/acp.rs
+++ b/src-tauri/src/core/cli/acp.rs
@@ -889,7 +889,16 @@ impl TurnMap {
/// stands on its own request id, which a client renders as a fresh card.
fn permission(&mut self, event: StreamEvent, match_calls: bool) -> Option<PermissionAsk> {
let StreamEvent::PermissionRequest {
- request_id, tool_name, capability, path, command, diff, offers_always, ..
+ request_id,
+ tool_name,
+ capability,
+ path,
+ command,
+ diff,
+ offers_always,
+ justification,
+ prompt_kind,
+ ..
} = event
else {
return None;
@@ -910,7 +919,13 @@ impl TurnMap {
call.prompted = true;
}
}
+ // An escalation is not the ordinary exec card: the client must see that
+ // approving it runs the command outside the sandbox.
+ let escalate = prompt_kind == "escalate";
let title = match (&command, &path) {
+ (Some(command), _) if escalate => {
+ format!("{tool_name} (outside the sandbox): {command}")
+ }
(Some(command), _) => format!("{tool_name}: {command}"),
(None, Some(path)) => format!("{tool_name} ({capability}) {path}"),
(None, None) => format!("{tool_name} ({capability})"),
@@ -921,6 +936,10 @@ impl TurnMap {
}
if let Some(diff) = diff {
fields = fields.content(vec![diff_block(&diff)]);
+ } else if let Some(why) = justification.filter(|_| escalate) {
+ fields = fields.content(vec![ToolCallContent::from(format!(
+ "Run outside the sandbox: {why}"
+ ))]);
}
Some(PermissionAsk {
tool_call: ToolCallUpdate::new(matched.unwrap_or_else(|| request_id.clone()), fields),
@@ -1094,6 +1113,7 @@ mod tests {
diff: None,
prompt_kind: "exec".into(),
offers_always: false,
+ justification: None,
}),
});
let wire: Vec<Value> = out.iter().map(wire).collect();
@@ -1104,6 +1124,31 @@ mod tests {
assert_eq!(wire[0]["toolCall"]["toolCallId"], "perm-7");
}
+ /// An escalation card says it runs outside the sandbox, carries the
+ /// model's reason, and offers no "always allow".
+ #[test]
+ fn an_escalation_prompt_says_where_it_runs_and_why() {
+ let mut map = map();
+ let out = map.map(StreamEvent::PermissionRequest {
+ request_id: "perm-9".into(),
+ tool_name: "shell".into(),
+ capability: "exec outside the sandbox".into(),
+ path: None,
+ command: Some("cargo build".into()),
+ diff: None,
+ prompt_kind: "escalate".into(),
+ offers_always: false,
+ justification: Some("fetch crates".into()),
+ });
+ let wire = wire(&out[0]);
+ assert_eq!(wire["always"], false);
+ assert_eq!(wire["toolCall"]["title"], "shell (outside the sandbox): cargo build");
+ assert_eq!(
+ wire["toolCall"]["content"][0]["content"]["text"],
+ "Run outside the sandbox: fetch crates"
+ );
+ }
+
#[test]
fn a_gate_prompt_attaches_to_the_oldest_open_call_of_its_tool() {
let mut map = map();
@@ -1120,6 +1165,7 @@ mod tests {
diff: Some("-a\n+b".into()),
prompt_kind: "write".into(),
offers_always: true,
+ justification: None,
});
wire(&out[0])
};
@@ -1312,6 +1358,7 @@ mod tests {
diff: None,
prompt_kind: "exec".into(),
offers_always: false,
+ justification: None,
}),
});
let w = wire(&out[0]);
diff --git a/src-tauri/src/core/cli/mod.rs b/src-tauri/src/core/cli/mod.rs
index a193d8eaf..42b973747 100644
--- a/src-tauri/src/core/cli/mod.rs
+++ b/src-tauri/src/core/cli/mod.rs
@@ -1315,6 +1315,7 @@ fn build_cli_orchestration_args(
plan: bool,
max_parallel_subagents: u32,
sandbox: Option<bool>,
+ allow_escalation: Option<bool>,
) -> OrchestrationArgs {
OrchestrationArgs {
client: crate::core::agent::upstream::agent_http_client(),
@@ -1359,6 +1360,9 @@ fn build_cli_orchestration_args(
// `--sandbox` only when passed; unset falls through to the project's
// `[tools].sandbox` and then the user's global `sandbox`.
sandbox,
+ // `--allow-escalation` only when passed; unset falls through to
+ // `[tools].allow_escalation`, then off.
+ allow_escalation,
// Filled in by `prepare_agent_session`, which is where the route's
// context window is resolved. The desktop paths leave it `None`: their
// window lives in the local engine's preset, not in a catalog this
@@ -1564,6 +1568,12 @@ pub struct SessionFlags {
/// to `[tools].sandbox`, then the global `sandbox`, then the CLI default of
/// off.
pub sandbox: Option<bool>,
+ /// `--allow-escalation`: run a sandboxed shell command that asks to leave
+ /// the sandbox without an escalation prompt (an exec approval `--safe`
+ /// requires anyway is still asked). `None` (not passed) defers to
+ /// `[tools].allow_escalation`, then off: escalation waits for a human
+ /// answer, which `auto_approve` does not give.
+ pub allow_escalation: Option<bool>,
/// `--worktree`: work in a dedicated git checkout. `None` (not passed)
/// defers to `[agent].worktree`, then the global `worktree`, then the CLI
/// default of off.
@@ -1889,6 +1899,7 @@ fn prepare_agent_session(
flags.plan,
max_parallel_subagents,
flags.sandbox,
+ flags.allow_escalation,
);
// Resolution order: configured `[agent].context_window` override, then what
@@ -2910,6 +2921,7 @@ async fn resolve_permission_silently(
capability,
path,
command,
+ justification,
..
} = ev
else {
@@ -2920,10 +2932,7 @@ async fn resolve_permission_silently(
if duplex {
return None;
}
- let detail = command
- .map(|c| format!(" ({c})"))
- .or_else(|| path.map(|p| format!(" on {p}")))
- .unwrap_or_default();
+ let detail = permission_detail(command, path, justification);
let decision = prompt_permission(tool_name, capability, detail).await;
if let Some(sender) = registry.lock().await.remove(&request_id) {
let _ = sender.send(decision);
@@ -3287,12 +3296,10 @@ async fn print_event(ev: StreamEvent, registry: &PermissionRegistry, duplex: boo
path,
command,
diff,
+ justification,
..
} => {
- let detail = command
- .map(|c| format!(" ({c})"))
- .or_else(|| path.map(|p| format!(" on {p}")))
- .unwrap_or_default();
+ let detail = permission_detail(command, path, justification);
if let Some(diff) = diff {
eprintln!("\x1b[2m{diff}\x1b[0m");
}
@@ -3327,6 +3334,24 @@ async fn print_event(ev: StreamEvent, registry: &PermissionRegistry, duplex: boo
}
}
+/// What a headless permission line names after the tool: the command or the
+/// path, then an escalation's reason, so a user approving a command outside
+/// the sandbox reads why the model wants it.
+fn permission_detail(
+ command: Option<String>,
+ path: Option<String>,
+ justification: Option<String>,
+) -> String {
+ let target = command
+ .map(|c| format!(" ({c})"))
+ .or_else(|| path.map(|p| format!(" on {p}")))
+ .unwrap_or_default();
+ match justification {
+ Some(why) => format!("{target} because: {why}"),
+ None => target,
+ }
+}
+
/// Ask the terminal to approve a gated tool call. Non-interactive stdin (pipe,
/// CI) auto-denies, matching the headless "safe default" contract; blocking
/// stdin is confined to a blocking thread so the loop task keeps running.
@@ -3360,6 +3385,19 @@ async fn prompt_permission(
mod tests {
use super::*;
+ /// The headless line names the command, then an escalation's reason.
+ #[test]
+ fn permission_detail_names_the_target_then_the_reason() {
+ let s = |v: &str| Some(v.to_string());
+ assert_eq!(permission_detail(s("ls"), None, None), " (ls)");
+ assert_eq!(permission_detail(None, s("a.txt"), None), " on a.txt");
+ assert_eq!(
+ permission_detail(s("cargo build"), None, s("fetch crates")),
+ " (cargo build) because: fetch crates"
+ );
+ assert_eq!(permission_detail(None, None, None), "");
+ }
+
/// The duplex channel end to end over a pipe: a follow-up is queued for the
/// steering handshake, a permission reply reaches the waiting run, a
/// malformed line is survivable, and `abort` stops the reader.
diff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rs
index 623df02a1..38a9c2859 100644
--- a/src-tauri/src/core/cli/tui.rs
+++ b/src-tauri/src/core/cli/tui.rs
@@ -614,6 +614,9 @@ struct Pending {
/// with the change in view; `None` for other tools.
diff: Option<String>,
offers_always: bool,
+ /// Why the model asks to run the command outside the sandbox, for an
+ /// escalation prompt; `None` for every other prompt.
+ justification: Option<String>,
/// Highlighted option in the docked prompt (index into `options()`).
selected: usize,
/// Name of the subagent that requested this, when the call originated inside
@@ -695,6 +698,15 @@ impl Pending {
vec![Span::styled(lead, dim)],
vec![Span::raw(" ")],
));
+ // The model's own words, set apart from the command so it is read as
+ // its claim rather than as part of what will run.
+ if let Some(why) = &self.justification {
+ out.extend(gutter_lines(
+ wrap_text(why, Style::new().italic(), max.saturating_sub(5).max(1)),
+ vec![Span::styled("why ", dim)],
+ vec![Span::raw(" ")],
+ ));
+ }
out
}
@@ -7608,6 +7620,7 @@ impl App {
command,
diff,
offers_always,
+ justification,
..
} => {
// Don't close the tool group here: the prompt renders docked
@@ -7621,6 +7634,7 @@ impl App {
command,
diff,
offers_always,
+ justification,
selected: 0,
subagent: None,
});
@@ -7970,6 +7984,7 @@ impl App {
command,
diff,
offers_always,
+ justification,
..
} => {
self.pending_queue.push_back(Pending {
@@ -7980,6 +7995,7 @@ impl App {
command,
diff,
offers_always,
+ justification,
selected: 0,
subagent: Some(name.to_string()),
});
@@ -25774,6 +25790,7 @@ mod tests {
command: Some("git status".into()),
diff: None,
offers_always,
+ justification: None,
selected: 0,
subagent: None,
}
@@ -26629,6 +26646,7 @@ mod tests {
diff: Some("@@ created file @@\n+ hi".into()),
prompt_kind: "write".into(),
offers_always: true,
+ justification: None,
});
let p = app.pending().unwrap();
assert_eq!(p.diff.as_deref(), Some("@@ created file @@\n+ hi"));
@@ -26663,6 +26681,7 @@ mod tests {
diff: None,
prompt_kind: "exec".into(),
offers_always: true,
+ justification: None,
});
assert!(app.pending().unwrap().diff_preview(60).is_empty());
}
@@ -31057,6 +31076,7 @@ mod tests {
run_mode: crate::core::agent::plan::RunMode::Normal,
session_id: None,
sandbox: None,
+ allow_escalation: None,
monitors: Some(app.monitor_set.clone()),
bg_shells: Some(app.shell_set.clone()),
subagent_bg: Some(app.subagent_set.clone()),
@@ -33471,6 +33491,7 @@ mod tests {
diff: None,
prompt_kind: "exec".into(),
offers_always: true,
+ justification: None,
},
));
assert_eq!(
@@ -33509,6 +33530,7 @@ mod tests {
diff: None,
prompt_kind: "exec".into(),
offers_always: true,
+ justification: None,
},
));
// Second subagent's request arrives while the first is still pending.
@@ -33524,6 +33546,7 @@ mod tests {
diff: None,
prompt_kind: "read".into(),
offers_always: false,
+ justification: None,
},
));
@@ -36208,6 +36231,7 @@ mod tests {
diff: None,
prompt_kind: "exec".into(),
offers_always: true,
+ justification: None,
});
app.pending_queue.clear(); // simulate approval
app.apply(StreamEvent::ToolResult {
@@ -42772,6 +42796,7 @@ mod tests {
diff: None,
prompt_kind: "write".into(),
offers_always: true,
+ justification: None,
}),
});
assert_eq!(app.status, Status::Parked, "the parent is still parked");
diff --git a/src-tauri/src/core/cli/tui/tests/snapshot.rs b/src-tauri/src/core/cli/tui/tests/snapshot.rs
index e6a9cbfdd..2685492ad 100644
--- a/src-tauri/src/core/cli/tui/tests/snapshot.rs
+++ b/src-tauri/src/core/cli/tui/tests/snapshot.rs
@@ -264,6 +264,7 @@ fn permission(app: &mut App, id: &str, command: &str) {
diff: None,
prompt_kind: "exec".into(),
offers_always: true,
+ justification: None,
});
}
@@ -278,6 +279,29 @@ fn permission_prompt_for_a_command() {
);
}
+/// An escalation shows the model's reason under the command and offers no
+/// "allow always".
+#[test]
+fn permission_prompt_to_escalate_out_of_the_sandbox() {
+ let mut app = snapshot_app();
+ start_turn(&mut app, "build it");
+ app.apply(StreamEvent::PermissionRequest {
+ request_id: "e1".into(),
+ tool_name: "shell".into(),
+ capability: "exec outside the sandbox".into(),
+ path: None,
+ command: Some("cargo build".into()),
+ diff: None,
+ prompt_kind: "escalate".into(),
+ offers_always: false,
+ justification: Some("cargo needs to write ~/.cargo/registry to fetch crates".into()),
+ });
+ assert_buffer(
+ "permission_prompt_escalate",
+ &frame(&mut app, DARK, 80, 20),
+ );
+}
+
#[test]
fn permission_prompt_from_a_subagent_with_a_queue() {
let mut app = snapshot_app();
@@ -294,6 +318,7 @@ fn permission_prompt_from_a_subagent_with_a_queue() {
diff: None,
prompt_kind: "write".into(),
offers_always: false,
+ justification: None,
}),
});
permission(&mut app, "p2", "ls");
@@ -326,6 +351,7 @@ fn permission_prompt_with_a_diff_on_ansi16() {
),
prompt_kind: "write".into(),
offers_always: true,
+ justification: None,
});
assert_buffer(
"permission_prompt_diff_ansi16",
diff --git a/src-tauri/src/core/cli/tui/tests/snapshots/permission_prompt_escalate.snap b/src-tauri/src/core/cli/tui/tests/snapshots/permission_prompt_escalate.snap
new file mode 100644
index 000000000..70f9ab1b2
--- /dev/null
+++ b/src-tauri/src/core/cli/tui/tests/snapshots/permission_prompt_escalate.snap
@@ -0,0 +1,65 @@
+---
+source: src/core/cli/tui/tests/snapshot.rs
+expression: render_snapshot(buf)
+---
+| ๐Ÿ‘‹ gpt-5-mini effort medium ctx 0K/128K fallback โ—‰ [working] |
+|โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€|
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+|โ•ญ permission required โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ|
+|โ”‚ shell wants exec outside the sandbox โ”‚|
+|โ”‚ $ cargo build โ”‚|
+|โ”‚ why cargo needs to write ~/.cargo/registry to fetch crates โ”‚|
+|โ”‚ โ–ถ Allow once โ”‚|
+|โ”‚ Deny โ”‚|
+|โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ|
+|> workingโ€ฆ (Esc to cancel, type to steer the agent) |
+| |
+|๐Ÿ“‚ /snapshot/repo โ†‘/โ†“ select Enter confirm Esc deny Ctrl-C cancel|
+
+ 0 0..2 fg=Yellow
+ 0 3..14 mod=BOLD
+ 0 14..29 fg=#E5C07B
+ 0 55..57 fg=#56B6C2
+ 0 57..66 fg=#56B6C2 mod=BOLD
+10 0..1 fg=#E5C07B
+10 1..22 fg=Black bg=#E5C07B mod=BOLD
+10 22..80 fg=#E5C07B
+11 0..1 fg=#E5C07B
+11 2..7 fg=Cyan mod=BOLD
+11 7..14 fg=DarkGray
+11 14..38 fg=Yellow mod=BOLD
+11 79..80 fg=#E5C07B
+12 0..1 fg=#E5C07B
+12 2..4 fg=DarkGray
+12 79..80 fg=#E5C07B
+13 0..1 fg=#E5C07B
+13 2..6 fg=DarkGray
+13 6..60 mod=ITALIC
+13 79..80 fg=#E5C07B
+14 0..1 fg=#E5C07B
+14 2..78 fg=Cyan mod=BOLD
+14 79..80 fg=#E5C07B
+15 0..1 fg=#E5C07B
+15 79..80 fg=#E5C07B
+16 0..80 fg=#E5C07B
+17 0..2 fg=#56B6C2 mod=BOLD
+17 2..3 mod=REVERSED
+17 4..12 mod=DIM | ITALIC
+17 18..59 mod=DIM | ITALIC
+19 0..1 fg=#808080
+19 2..17 fg=#808080
+19 27..30 fg=#E5C07B mod=BOLD
+19 30..37 mod=DIM
+19 40..45 fg=#E5C07B mod=BOLD
+19 45..53 mod=DIM
+19 56..59 fg=#E5C07B mod=BOLD
+19 59..64 mod=DIM
+19 67..73 fg=#E5C07B mod=BOLD
+19 73..80 mod=DIM
diff --git a/src-tauri/src/core/mcp/server/mod.rs b/src-tauri/src/core/mcp/server/mod.rs
index c0d9d294a..1e23056da 100644
--- a/src-tauri/src/core/mcp/server/mod.rs
+++ b/src-tauri/src/core/mcp/server/mod.rs
@@ -283,6 +283,17 @@ impl JanToolServer {
Vec::new(),
);
}
+ // The served shell runs under the sandbox the server was started
+ // with; an external caller cannot lift it, for the same reason.
+ Decision::Prompt(PromptKind::Escalate) => {
+ return (
+ format!(
+ "ERROR: tool '{name}' was refused: running outside the sandbox needs \
+ the user's approval, which an external caller cannot give."
+ ),
+ Vec::new(),
+ );
+ }
}
let ctx = self.tool_context();
let (content, images) = execute_builtin(tool, args, &ctx).await;