Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a9e7562
feat: add experimental child sandboxes for sub-agents (RFC 0021)
patkraw Nov 13, 2026
f54f2f3
refactor(server): replace MCP background jobs with a detach recipe in…
patkraw Nov 23, 2026
84f34c7
fix(server): skip child sandbox work when the feature is off
patkraw Nov 26, 2026
1a5d61e
fix(api): mark child sandbox fields, flags and settings experimental
patkraw Nov 26, 2026
42ab37d
docs(gateway): say what happens to children when the flag is off
patkraw Nov 26, 2026
dbcd6ee
docs(sandboxes): warn to delete children before a gateway rollback
patkraw Nov 26, 2026
5fee42e
feat(server): give the MCP tools a per-role schema and output schemas
patkraw Nov 26, 2026
c212bf4
refactor(server): copy root policy changes to all children at once
patkraw Nov 27, 2026
ac14dfe
docs(sandboxes): say MCP bypasses network policy and templates can ad…
patkraw Nov 27, 2026
d53980a
fix: build child sandboxes against current main
patkraw Nov 27, 2026
590e6bc
fix(server): let a root started under a global policy have children
patkraw Nov 28, 2026
722d242
fix: keep a root until its children's deletes finish
patkraw Nov 28, 2026
cda6cca
docs(sandboxes): link the issue tracking children that keep a rejecte…
patkraw Nov 30, 2026
f29b918
chore: merge main into child sandboxes branch
patkraw Dec 2, 2026
fce0116
fix: unbreak CI for child sandboxes
patkraw Dec 2, 2026
31b834f
chore: merge main into child sandboxes branch
patkraw Dec 3, 2026
9b15543
fix: refresh the Docker driver suite lockfile
patkraw Dec 3, 2026
28603e7
fix(server): record the user a sandbox was created on behalf of
patkraw Dec 3, 2026
2fd7892
refactor(server): drop leftovers from removed child sandbox code
patkraw Dec 3, 2026
9e441bd
fix(server): do no child sandbox work when the feature is off
patkraw Dec 3, 2026
1f52b06
fix(cli): stop listing children before every sandbox delete
patkraw Dec 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/e2e-docker-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ on:
required: false
type: string
default: >-
[{"suite":"oidc-pkce-docker","cmd":"mise run --no-deps --skip-deps e2e:oidc-pkce:docker","apt_packages":"openssh-client","mcp":false},{"suite":"rust-docker","cmd":"mise run --no-deps --skip-deps e2e:rust","apt_packages":"openssh-client","mcp":false},{"suite":"oci-image","cmd":"mise run --no-deps --skip-deps e2e:oci-image","apt_packages":"openssh-client","mcp":false},{"suite":"additional-ca","cmd":"OPENSHELL_E2E_DOCKER_TEST=additional_ca mise run --no-deps --skip-deps e2e:docker","apt_packages":"openssh-client","mcp":false},{"suite":"middleware-http-hooks","cmd":"mise run --no-deps --skip-deps e2e:middleware-http-hooks","apt_packages":"","mcp":false},{"suite":"mcp","cmd":"mise run --no-deps --skip-deps e2e:mcp","apt_packages":"","mcp":true}]
[{"suite":"oidc-pkce-docker","cmd":"mise run --no-deps --skip-deps e2e:oidc-pkce:docker","apt_packages":"openssh-client","mcp":false},{"suite":"rust-docker","cmd":"mise run --no-deps --skip-deps e2e:rust","apt_packages":"openssh-client","mcp":false},{"suite":"rust-docker-child-sandboxes","cmd":"mise run --no-deps --skip-deps e2e:rust:child-sandboxes","apt_packages":"openssh-client","mcp":false},{"suite":"oci-image","cmd":"mise run --no-deps --skip-deps e2e:oci-image","apt_packages":"openssh-client","mcp":false},{"suite":"additional-ca","cmd":"OPENSHELL_E2E_DOCKER_TEST=additional_ca mise run --no-deps --skip-deps e2e:docker","apt_packages":"openssh-client","mcp":false},{"suite":"middleware-http-hooks","cmd":"mise run --no-deps --skip-deps e2e:middleware-http-hooks","apt_packages":"","mcp":false},{"suite":"mcp","cmd":"mise run --no-deps --skip-deps e2e:mcp","apt_packages":"","mcp":true}]

permissions:
actions: read
Expand Down
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/openshell-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ prost = { workspace = true }
prost-types = { workspace = true }

# Async runtime
async-trait = "0.1"
tokio = { workspace = true }

# gRPC client
Expand Down
1 change: 1 addition & 0 deletions crates/openshell-cli/src/completers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub fn complete_sandbox_names(_prefix: &OsStr) -> Vec<CompletionCandidate> {
page_size: 200,
page_token: String::new(),
label_selector: String::new(),
parent: String::new(),
workspace_scope: Some(openshell_core::proto::workspace_selector(
workspace_from_args(),
)),
Expand Down
1 change: 1 addition & 0 deletions crates/openshell-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod callback;
pub mod color;
pub(crate) mod commands;
pub mod completers;
pub mod mcp_bridge;
pub mod oidc_auth;
pub mod output;
pub(crate) mod policy_update;
Expand Down
187 changes: 185 additions & 2 deletions crates/openshell-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,74 @@ fn apply_auth_with_status(tls: &mut TlsOptions, gateway_name: &str) -> Option<St
}
}

/// The bridge's gateway client, refreshing an OIDC login for as long as the
/// bridge runs, or why there is none.
async fn mcp_client(
gateway: &Option<String>,
gateway_endpoint: &Option<String>,
allow_endpoint_override: bool,
tls: TlsOptions,
) -> std::result::Result<openshell_sdk::OpenShellClient, String> {
let ctx = resolve_gateway(gateway, gateway_endpoint, allow_endpoint_override)
.map_err(|error| error.to_string())?;
let mut tls = tls.with_gateway_name(&ctx.name);
if let Some(error) = apply_auth_with_status(&mut tls, &ctx.name) {
return Err(error);
}
let refresher = get_gateway_metadata(&ctx.name)
.filter(|meta| meta.auth_mode.as_deref() == Some("oidc"))
.map(|meta| {
let refresher: std::sync::Arc<dyn openshell_sdk::Refresh> =
std::sync::Arc::new(openshell_cli::mcp_bridge::StoredOidcRefresher {
gateway_name: ctx.name.clone(),
audience: meta.oidc_audience,
scopes: meta.oidc_scopes,
insecure: tls.gateway_insecure,
});
refresher
});
openshell_cli::tls::sdk_client(&ctx.endpoint, &tls, refresher)
.await
.map_err(|error| format!("cannot reach the gateway: {error}"))
}

/// Run the MCP bridge. Missing or unusable credentials do not stop it: each
/// call then answers with what to run, so the MCP client shows the reason,
/// and nothing ever starts an interactive login. The client is built on the
/// first call that can build it, so a login made after the bridge started
/// takes effect without restarting it.
async fn mcp_serve(
gateway: &Option<String>,
gateway_endpoint: &Option<String>,
allow_endpoint_override: bool,
tls: TlsOptions,
workspace: String,
) -> Result<()> {
let (gateway, gateway_endpoint) = (gateway.clone(), gateway_endpoint.clone());
let client = std::sync::Arc::new(openshell_cli::mcp_bridge::LazyClient::new(move || {
let (gateway, gateway_endpoint, tls) =
(gateway.clone(), gateway_endpoint.clone(), tls.clone());
async move { mcp_client(&gateway, &gateway_endpoint, allow_endpoint_override, tls).await }
}));
// Try once at start so a missing login shows on stderr straight away.
if let Err(error) = client.get().await {
eprintln!("openshell mcp serve: {error}");
}
let workspace = std::sync::Arc::new(workspace);
let send = move |body: Vec<u8>| {
let client = std::sync::Arc::clone(&client);
let workspace = std::sync::Arc::clone(&workspace);
async move { openshell_cli::mcp_bridge::send_with(client.get().await, &body, &workspace).await }
};
openshell_cli::mcp_bridge::serve(
tokio::io::BufReader::new(tokio::io::stdin()),
tokio::io::stdout(),
send,
)
.await
.map_err(|error| miette::miette!("MCP stdio failed: {error}"))
}

/// Resolve a sandbox name, falling back to the last-used sandbox for the
/// gateway and workspace.
///
Expand Down Expand Up @@ -660,6 +728,13 @@ enum Commands {
output: OutputFormat,
},

/// Serve the gateway's sandbox tools to a local MCP client (experimental).
#[command(help_template = SUBCOMMAND_HELP_TEMPLATE)]
Mcp {
#[command(subcommand)]
command: Option<McpCommands>,
},

/// Show the identity validated by the gateway.
#[command(help_template = LEAF_HELP_TEMPLATE, next_help_heading = "FLAGS")]
Whoami {
Expand Down Expand Up @@ -1494,6 +1569,18 @@ enum GatewayCommands {
// Doctor (diagnostic) commands
// -----------------------------------------------------------------------

#[derive(Subcommand, Debug)]
enum McpCommands {
/// Run a local MCP server over stdio for an MCP client.
///
/// Add it to the client's configuration as the command
/// `openshell mcp serve`. Each tool call goes to the active gateway with
/// this CLI's login, acting in `--workspace`. The gateway serves the tools
/// only when `experimental_enable_child_sandboxes` is on.
#[command(help_template = LEAF_HELP_TEMPLATE, next_help_heading = "FLAGS")]
Serve,
}

#[derive(Subcommand, Debug)]
enum DoctorCommands {
/// Validate system prerequisites for running a gateway.
Expand Down Expand Up @@ -1525,6 +1612,12 @@ enum SandboxCommands {
#[arg(long, conflicts_with_all = ["from", "gpu", "cpu", "memory", "driver_config_json", "envs", "env_from"])]
template: Option<String>,

/// Experimental: create the sandbox as a child of this root sandbox.
/// The child uses the parent's policy, and `--provider` picks from
/// the parent's providers (all of them when omitted).
#[arg(long, add = ArgValueCompleter::new(completers::complete_sandbox_names))]
parent: Option<String>,

/// Sandbox source: a rootfs tar archive (`.tar`, `.tar.gz`, or `.tgz`)
/// or a container image reference (e.g., `myregistry.com/img:tag`).
///
Expand Down Expand Up @@ -1767,6 +1860,10 @@ enum SandboxCommands {
#[arg(long)]
selector: Option<String>,

/// Experimental: list only the child sandboxes of this root sandbox.
#[arg(long, conflicts_with = "all_workspaces", add = ArgValueCompleter::new(completers::complete_sandbox_names))]
parent: Option<String>,

/// Output format.
#[arg(short = 'o', long = "output", value_enum, default_value_t = OutputFormat::Table, conflicts_with_all = ["ids", "names"])]
output: OutputFormat,
Expand Down Expand Up @@ -2885,9 +2982,17 @@ async fn run_async() -> Result<()> {

// The fmt formatter defaults to ANSI on with no terminal detection, and it
// writes to stdout, so without this `openshell -v ... | ...` pipes escapes
// to the caller.
// to the caller. The MCP bridge's stdout carries MCP messages only, so it
// logs to stderr.
let mcp = matches!(cli.command, Some(Commands::Mcp { .. }));
let writer = if mcp {
tracing_subscriber::fmt::writer::BoxMakeWriter::new(std::io::stderr)
} else {
tracing_subscriber::fmt::writer::BoxMakeWriter::new(std::io::stdout)
};
tracing_subscriber::fmt()
.with_ansi(color::stdout_enabled())
.with_ansi(!mcp && color::stdout_enabled())
.with_writer(writer)
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new(log_level)),
Expand Down Expand Up @@ -3040,6 +3145,29 @@ async fn run_async() -> Result<()> {
}
}

// -----------------------------------------------------------
// MCP bridge
// -----------------------------------------------------------
Some(Commands::Mcp {
command: Some(McpCommands::Serve),
}) => {
mcp_serve(
&cli.gateway,
&cli.gateway_endpoint,
explicit_gateway == explicit_endpoint,
tls,
cli.workspace,
)
.await?;
}
Some(Commands::Mcp { command: None }) => {
Cli::command()
.find_subcommand_mut("mcp")
.expect("mcp subcommand exists")
.print_help()
.expect("Failed to print help");
}

// -----------------------------------------------------------
// Top-level current identity
// -----------------------------------------------------------
Expand Down Expand Up @@ -3625,6 +3753,7 @@ async fn run_async() -> Result<()> {
SandboxCommands::Create {
name,
template,
parent,
from,
upload,
no_git_ignore,
Expand Down Expand Up @@ -3727,6 +3856,7 @@ async fn run_async() -> Result<()> {
run::SandboxCreateConfig {
name: name.as_deref(),
template: template.as_deref(),
parent: parent.as_deref(),
from: from.as_deref(),
uploads: &upload_specs,
keep,
Expand Down Expand Up @@ -3837,6 +3967,7 @@ async fn run_async() -> Result<()> {
ids,
names,
selector,
parent,
output,
all_workspaces,
} => {
Expand All @@ -3847,6 +3978,7 @@ async fn run_async() -> Result<()> {
ids,
names,
selector.as_deref(),
parent.as_deref(),
output.as_str(),
&cli.workspace,
all_workspaces,
Expand Down Expand Up @@ -7105,6 +7237,57 @@ mod tests {
}
}

#[test]
fn sandbox_list_parent_flag_parses_and_needs_one_workspace() {
let cli = Cli::try_parse_from(["openshell", "sandbox", "list", "--parent", "lead"])
.expect("sandbox list parent flag should parse");
assert!(matches!(
cli.command,
Some(Commands::Sandbox {
command: Some(SandboxCommands::List { parent: Some(ref parent), .. }),
}) if parent == "lead"
));

let err = Cli::try_parse_from([
"openshell",
"sandbox",
"list",
"--parent",
"lead",
"--all-workspaces",
])
.expect_err("--parent needs a single workspace");
assert_eq!(err.kind(), clap::error::ErrorKind::ArgumentConflict);
}

#[test]
fn sandbox_create_parent_flag_parses() {
let cli = Cli::try_parse_from([
"openshell",
"sandbox",
"create",
"--parent",
"lead",
"--provider",
"github",
])
.expect("sandbox create parent flag should parse");

match cli.command {
Some(Commands::Sandbox {
command:
Some(SandboxCommands::Create {
parent, providers, ..
}),
..
}) => {
assert_eq!(parent.as_deref(), Some("lead"));
assert_eq!(providers, vec!["github".to_string()]);
}
other => panic!("expected SandboxCommands::Create, got: {other:?}"),
}
}

#[test]
fn sandbox_create_template_conflicts_with_inline_workload_flags() {
for (label, extra_args) in [
Expand Down
Loading