Repository navigation
Conversation
A root sandbox can have depth-1 child sandboxes that share its policy and a subset of its providers. Users create them with sandbox create --parent; agents in a root manage them through MCP tools at openshell.local/mcp; host users reach the same tools through openshell mcp serve. Off by default (experimental_enable_child_sandboxes). Signed-off-by: patkraw <[email protected]>
… exec Remove the wait tool, the background argument of exec, and the jobs module that ran them. The exec tool's description now tells the caller to start long work detached in the sandbox and check on it with later exec calls. The gateway keeps no job state and runs no job script in a child. The e2e test starts a detached command and collects its result. The docs page describes the steps in full. Signed-off-by: patkraw <[email protected]>
9b4334a to
5845890
Compare
pimlock
left a comment
There was a problem hiding this comment.
Design-level pass on the parts I'm confident about so far; more to follow on the policy sync model (copy timing, revocation while the parent is stopped) and on the per-root opt-in.
|
|
||
| if let Some(enabled) = file | ||
| .as_ref() | ||
| .and_then(|f| f.openshell.gateway.experimental_enable_child_sandboxes) |
There was a problem hiding this comment.
Consider requiring config push when child sandboxes are enabled.
The sync re-pushes every child after copying, but publish_sandbox returns early under config_delivery_mode = "poll", so children pick up the parent's change only on their next poll, up to one interval after the parent loaded it. Since polling goes away in 0.2.0 (#4498), it seems reasonable to require config_delivery_mode = "push" when experimental_enable_child_sandboxes is on: refuse to start otherwise, and serve an unadmitted config to a child whose supervisor does not support push.
If you do, please make sure a failed sync is still retried. Today that retry comes from the periodic poll rebuild; I have not checked whether push sessions get an equivalent. Doing the copy inside the config build when the gate finds the child behind would make the republish itself the retry.
Low priority, not blocking.
| SandboxWorkloadTemplateProvenance created_from_workload_template = 20; | ||
| // Read-only parent of a child sandbox, set by the gateway at creation. | ||
| // Absent on root sandboxes. Never changes. | ||
| SandboxParent parent = 21; |
There was a problem hiding this comment.
experimental_enable_child_sandboxes gates the behavior, but the contract ships unmarked: Sandbox.parent, Sandbox.created_by, CreateSandboxRequest.parent, ListSandboxesRequest.parent and SandboxParent land in openshell.v1 with no EXPERIMENTAL note, and so do sandbox create/list --parent and the max_concurrent_children gateway key.
After the next release these are frozen, while the RFC still leaves depth > 1 and policy narrowing open. Could you mark the fields and the message EXPERIMENTAL (as done at openshell.proto:2845), label or hide --parent, and either prefix the key (experimental_max_concurrent_children) or nest both keys under an experimental table?
| // Read-only identity of who created this sandbox, set by the gateway: the | ||
| // user who created it, or `sandbox:<id>` when a sandbox created it over | ||
| // MCP. Empty on sandboxes created before this field existed. | ||
| string created_by = 22; |
There was a problem hiding this comment.
created_by holds either an OIDC subject or sandbox:<id>, and the authz code (check_creator_has_access, acting_for in mcp.rs) reads it as a subject. SDK consumers have to parse a prefix that a user subject could also carry, and it stores a raw id where parent uses {name, id}.
Consider a typed creator, for example oneof creator { string user_subject = 1; SandboxParent sandbox = 2; }, or keep this as the user subject and record the creating sandbox separately.
| description: &'static str, | ||
| } | ||
|
|
||
| const TOOLS: &[Tool] = &[ |
There was a problem hiding this comment.
The MCP tools become a third API surface with no versioned contract:
- users and sandboxes get the same
tools/list, and role-only arguments are marked only in prose ("users only"); - results (
timed_out,already_existed,deleting) have nooutputSchema; - there is no stability statement, and the SDK exposes the replies as raw bytes.
Could you emit the tool schema per caller role, declare outputSchema, and document the tools (and post_mcp in the SDK) as experimental?
| Child sandboxes are experimental. A gateway operator enables them, and the MCP tools, with `experimental_enable_child_sandboxes`. Refer to [Gateway Configuration](/how-it-works/gateways/configuration#child-sandboxes). | ||
| </Note> | ||
|
|
||
| ## Roots and Children |
There was a problem hiding this comment.
Please document the upgrade and rollback constraint here.
The parent link lives only in field 21 of the stored Sandbox. A gateway that predates it (a rollback, or an old replica during a rolling update) drops the unknown field when it rewrites the record, for example on a policy-status report. From then on the child is a root on every gateway version, with its policy and providers no longer tied to the parent. Users should delete child sandboxes before rolling back to a version without child support or running mixed gateway versions.
| .store | ||
| .supersede_older_policies(sandbox_id, i64::from(newest_loaded)) | ||
| .await; | ||
| // A root now enforces a new policy: copy it into its children. |
There was a problem hiding this comment.
[should] Gateways with the feature off still pay for it. Every policy load on a root (policy.rs:5562), and every failed load under fail-closed, starts a child sync. That sync takes the parent's lock and decodes every sandbox in the workspace. Deleting a root counts children the same way, and startup scans every workspace. None of these paths checks the flag.
Summary
Adds child sandboxes: a root sandbox can have depth-1 child sandboxes that use its policy and a subset of its providers, so an agent can run sub-agents in their own sandboxes. This is the implementation of RFC 0021 "Sandboxed Subagents", opened as a draft so the team can try the feature while the RFC is in review. It is off unless the operator sets
experimental_enable_child_sandboxes.Size note: GitHub overstates the removed lines.
crates/openshell-server/src/grpc/sandbox.rsreally has about 5,240 added and 98 removed (git diff --diff-algorithm=patience), and more than half of the added lines in this PR are tests.Related Issue
Closes #4574
The RFC pull request (#4721) also references #4574. If maintainers prefer a separate implementation issue, I will re-link this PR.
Changes
experimental_enable_child_sandboxes(defaultfalse) andmax_concurrent_children(default 10) ingateway.toml; read-onlySandbox.parentandSandbox.created_by;CreateSandboxRequest.parent. Records without a parent read as roots, so there is no migration.sandbox create --parent <root>andsandbox list --parent <root>;sandbox listshows aPARENTcolumn when a page holds a child.http://openshell.local/mcpinside each sandbox and forwards it to the gateway's new/mcpendpoint with the sandbox's session token; the agent holds no credential. Five tools (create_sandbox,list,exec,delete,logs) each run as the existing RPC through the normal gRPC stack, so authentication, authorization, rate limits and interceptors apply. A sandbox caller reaches only these methods, only through/mcp, and only for its own children.execruns in the foreground for at most 45 seconds. Its description tells the caller to start longer work detached in the sandbox and check on it with laterexeccalls. The gateway keeps no job state./mcpaccepts user callers, andopenshell mcp serveis a stdio bridge that reuses the CLI login and connection.openshell.ai/agent-usable=true; it cannot name an image.docs/how-it-works/sandboxes/child-sandboxes.mdx, the gateway configuration reference, the templates page and the CLI skill.OPENSHELL_EXPERIMENTAL_CHILD_SANDBOXES=1 mise run gateway:dockerturns the feature on in the dev gateway.How to try it
docs/4574-child-sandboxes-examples/patkrawfrompatkraw/OpenShell. It is this PR's first commit plus tutorials and runnable scenarios, which are not part of this PR.examples/child-sandboxes/tutorials, starting with00-setup.md. Seven short tutorials cover the CLI, MCP from inside a root, background jobs, templates, policy and provider sync, and MCP from the host. The tutorials branch still has the earlierwaittool; its background-jobs tutorial does not match this PR until it is updated.experimental_enable_child_sandboxes = trueunder[openshell.gateway]and restart it.openshell workspace member add --workspace <ws> --subject <user> --role user.Design notes: long-running work
This PR ships the "plain" approach: no
waittool and nobackgroundargument. The caller starts long work detached withsetsid, writes output and the exit code to files, and reads them with laterexeccalls. An earlier version of this PR had gateway-managed jobs ("managed"); the second commit removes them, about 900 lines, so the gateway keeps no job state and runs no job script in a child.Two experiments with lead agents driving child sandboxes compared the approaches. Both reports are on the tutorials branch.
The
execdescription is the short text from the experiments.docs/how-it-works/sandboxes/child-sandboxes.mdxhas the full steps, which weaker models may need in their instructions. A skill with those steps is a possible follow-up.To do before merge
mainfor development builds after this PR was opened. A child gets a copy of its parent's policy, and that path has not been run with a parent that uses a Cedar policy.Known limits
execthat reaches its timeout is reported as timed out but keeps running until the child is deleted (existingExecSandboxbehaviour, ExecSandbox processes keep running after execution_timeout and after the client disconnects #5042). Detached work depends on a process outliving its exec; a future cleanup of exec'd processes needs a detach option first.ps./mcp.Testing
Run on a macOS arm64 development machine, on both commits rebased onto
mainat152c59d31:cargo clippy --workspace --all-targets -- -D warningsand the same fore2e/rust: clean.cargo fmt --all -- --check: clean.mise run e2e:rust:child-sandboxes(Docker gateway): 6 of 6 passed. One test starts a detached command through MCP and collects its result.cargo testforopenshell-server,openshell-cli,openshell-sdk,openshell-supervisor-network,openshell-coreandopenshell-gateway-interceptors:openshell-serverpasses. The failures are tests that also fail onmainon this machine: 4 inopenshell-core(e2fsprogstool checks that time out), 8 inopenshell-supervisor-networkproxy tests, theopenshell-clisandbox-create tests that wait on helper processes, and threeprovider_readiness_update_polls_later_targets_*timing tests that are intermittent onmain.waittool was removed.Not run: Linux-only tests (Landlock, seccomp), the Podman, Kubernetes and VM lanes, and the PostgreSQL multi-replica tests. CI is expected to cover the first.
Checklist