Skip to content

Latest commit

 

History

History
384 lines (307 loc) · 23.8 KB

openshell-sandbox.md

File metadata and controls

384 lines (307 loc) · 23.8 KB

OpenShell SandboxDriver

Development requires OpenShell v0.1.9, the pinned OCE runtime, Kubernetes Compute, and dedicated Codex or native OpenClaw. Embedded OpenClaw is unsupported. OCC owns Agents, revisions, Namespaces, routing, credentials, and authorization. A Credential Gateway or Credential Proxy delivers model credentials; see implementation status. Revision Providers supply enrollment and Codex files. Production qualification remains open.

See setup for Namespace-owned gateways. Settings below cover operator-owned gateways.

Ownership model

Kubernetes Compute retains baseline isolation, storage, routing, and the per-Agent Gateway. Sandbox owns:

  • supportsHarnessExecutionMode declares OpenClaw support. Operator mode requires kubernetes.userNamespaces: false and at most one ServiceAccount in gateway.operatorWorkspaceResources; see mode support and managed-mode bootstrap.
  • configureAgent pins either dedicated Harness’s main workspace to the Sandbox data mount before OCC saves the revision. Codex retains app-server containment policy.
  • validateWorkspaceSetup admits initial files only for that workspace and one main Agent (or no roster). Compute checks storage and identity; Sandbox initializes the mount.
  • In operator mode, ensureNamespace applies labels, workspace resources, and NetworkPolicies and owns the active Workspace. A preprovisioned namespace only verifies them.
  • provisionHarness creates and returns a Sandbox with credential attachments and a runtime Provider, validating Codex routing. Codex exposes app-server; native OpenClaw connects outward to Gateway and may expose a failure endpoint until enrollment. Workspace initialization precedes execution.
  • provisionStagedHarness creates an idle Sandbox for managed credentials. After policy and Provider readiness, Compute installs launch inputs with prepareStagedHarness. activateStagedHarness passes current Provider placeholders via fresh ExecSandbox; the supervisor starts the Harness.
  • OpenShell's controller creates and owns the Sandbox's Harness Pod.
  • cleanup derives Sandbox identity on retirement, even without its Pod. Namespace cleanup verifies ownership and removes the Workspace and configured resources before Compute deletes the namespace.

Compute serves only ready workloads with matching revision routes. Workers provision and clean up by stored sandboxDriverId.

OpenShell containment facets

Containment facets:

Facet Current OpenShell behavior
networking Binary-scoped OpenShell policies for Harness tool traffic, plus Kubernetes baseline policies.
filesystem Approved PVC subpath mounts and OpenShell filesystem policy for read-only/read-write paths.
process OpenShell runs the workload with the UID and GID selected by its driver.

policy.landlockCompatibility must be omitted or hard_requirement. Other values fail startup. Hosts lacking required Landlock operations fail launch.

exec runs inside the Harness sandbox. An exec facet, command authorization and per-tool sandboxes are deferred.

Configuration

Select drivers.sandbox with Kubernetes Compute. The openshell Backend must list the Sandbox ID and, if selected, the Credential Gateway ID. For managed delivery, OCC registers Sandbox and Credential Proxy together; Proxy exposes credential_proxy_delivery. Configure the Gateway connection and WSS CA (rootCertificatePath) on the Backend.

drivers:
  compute:
    id: compute-kubernetes
    configuration:
      # See kubernetes-compute.md.

  sandbox:
    id: openshell-sandbox
    configuration:
      integrationMode: legacy
      gateway:
        operatorNamespaceLabels:
          openshell.ai/openclaw-workspace: "true"
        operatorWorkspaceResources: []
        networkPolicyResources: []
      kubernetes:
        userNamespaces: false
        serviceAccount:
          mode: gatewayConfigured
        sandboxDataMount:
          subPath: workspace
          mountPath: /sandbox/enterprise
          readOnly: false
      policy:
        process:
          runAsUser: "1000"
          runAsGroup: "1000"
        networkPolicies:
          - name: source-control
            binaries:
              - path: /usr/bin/git
            endpoints:
              - host: github.com
                ports: [443]
                protocol: tcp
                tls: skip

Without policy.filesystem, read-only paths include /bin, /usr, /lib, /proc, /dev/urandom, /etc, /var/log, /app, and /opt/devtools. Writable paths include /tmp, /dev/null, the image workdir, approved mounts, and /sandbox/.openclaw-runtime.

An explicit policy replaces defaults; the Driver adds required mounts, the runtime root, and /tmp. Include /opt/devtools in policy.filesystem.readOnly for packaged native tools. Deploy a new revision to change an existing Sandbox’s launch policy.

Startup rejects unknown Kubernetes, policy, and Gateway readiness keys. Use quoted non-negative quantities in kubernetes.agentResources. Sizing uses spec.template.resources; operator mounts remain in spec.template.driver_config. Ephemeral-storage defaults are 256Mi request and 1Gi limit. Provider templates can override sizing; verify the rendered container resources. Legacy adoption and maintenance reject sizing in driver_config. Redeploy after upgrading. See service-mode recovery.

In operator mode, kubernetes.agentResourceOverrides binds exact namespaceId and agentId pairs. Set cpu or memory in requests and limits. Omitted keys inherit agentResources. Startup rejects malformed IDs, duplicates, and requests above limits. Check scheduling before redeploying. Adoption requires an exact spec. Configure RuntimeClass in Kubernetes or OpenShell.

Set policy.process.runAsUser and runAsGroup. The pinned OpenShell runs Sandbox processes as the workload identity, normally 10001:10001.

The credential provider already configures TLS inspection for api.openai.com. An uninspected rule for that host conflicts.

Use unique network policy names and nonempty executable paths. workspace-node-enrollment is reserved. Options include enforcement: enforce|audit and access: read_only|read_write|full. Omit tls for automatic TLS inspection; tls: skip bypasses inspection. The pinned gateway rejects explicit terminate and passthrough. An endpoint protocol is tcp, rest, websocket, graphql or sql in any case (OCE sends it lowercase), or omitted. tcp takes neither access nor enforcement; the other protocols need access, and sql allows only enforcement: audit. json-rpc and mcp need rules this setting cannot express, so startup refuses them. gatewayConfigured is the only ServiceAccount mode; the gateway's configured sandbox ServiceAccount applies to every Sandbox and does not satisfy the per-Agent production requirement below.

Protected Codex artifact rules

For protected, dedicated Codex repository execution, select approved artifact rules with policy.codexArtifactRuleNames, for example codexArtifactRuleNames: [codex-plugin-artifacts]. Each name must identify exactly one existing policy.networkPolicies rule. Omission grants no artifact access.

Selected rules require the bundled Codex executable paths, exact DNS hosts, port 443, protocol: rest, enforcement: enforce and access: read_only. Omit tls for verified REST TLS inspection. Admission refuses explicit skip and deprecated termination modes. Wildcards, numeric addresses, GitHub repository hosts, reserved names and credential/provider fields are refused.

Admission freezes only that qualified map with empty Agent additions. Preparation and replay use the revision, even if Installation defaults change. Select a new revision to change artifact authority. Live Agent policy apply remains unavailable.

Gateway readiness and workspace

Optional readiness observes an OCC-namespace Service/Pods; paired Gateways normally use Backend endpoint. Require positive timeoutMs and pollIntervalMs ≤ 2147483647 (default 1000). Development uses Harness readiness without startupDelayMs.

Install OpenShell separately. integrationMode selects legacy (default) or service, independently of OpenShell's workspace mode. OCE rejects gateway.workspaceMode.

For legacy integration, configure the Gateway's Kubernetes driver with workspaceMode: operator, a namespace selector matching operatorNamespaceLabels, and allowed_pod_labels listing openclaw.dev/*, app.kubernetes.io/name, and app.kubernetes.io/managed-by; otherwise deployment fails with SANDBOX_POD_LABELS_NOT_PERMITTED. Workspace names match pre-provisioned namespaces: oce- plus a 15-character digest.

The development profile installs a Gateway without workspace resources in oce-system (Kubernetes-only) or openshell-system (Compose), and Agent Sandbox in agent-sandbox-system. The launcher renders openshell-workspace into trusted Installation configuration once; the Driver applies it before Workspace creation without per-Namespace Helm releases.

Kubernetes-only installations enable Gateway TLS, mTLS and authentication; static inference requires opt-in. Compose permits unauthenticated Gateway access. Control-plane RPCs and Harness traffic share a port; NetworkPolicies cannot give Agent Gateways service-only authority. Use only owned disposable development clusters.

gateway.operatorWorkspaceResources accepts workspace ServiceAccount, Role, RoleBinding and NetworkPolicy manifests; gateway.networkPolicyResources accepts namespaced provider networking manifests. Operator ensureNamespace applies both server-side to the Compute-owned namespace with OCC ownership metadata; preprovisionedNamespace only compares. Startup rejects Secrets, NetworkPolicy ingress _from (use from), and fields the Kubernetes client drops or changes (misspelled selector keys, LimitRange default). Neither list permits OpenShell credentials or cluster-scoped objects.

kubernetes.sandboxDataMount must match exactly one approved dedicated Harness workspace mount. It may not mount the PVC root or use .., and must mount under /sandbox/. For native OpenClaw, the permission preparer creates that subpath before Sandbox creation. After supervisor readiness, Sandbox initializes private workspace inputs through private stdin; the Harness verifies completion at its effective path.

For dedicated Codex, OpenShell's configureAgent hook removes appServer.networkProxy and adds this before OCC validates and saves the Agent revision:

{
  "plugins": {
    "entries": {
      "codex": {
        "enabled": true,
        "config": {
          "appServer": {
            "sandbox": "danger-full-access",
            "approvalsReviewer": "user"
          }
        }
      }
    }
  }
}

Codex requires danger-full-access mode, the :danger-full-access profile, and user review. Readiness refusal produces RUNTIME_CODEX_PERMISSION_POLICY_INCOMPATIBLE with fixed worker diagnostic categories. The read limits distinguish RUNTIME_CODEX_REQUIREMENTS_TOO_LARGE from incomplete evidence. OpenShell isolates all login modes and blocks restricted profiles' nested bubblewrap namespaces. The Gateway rejects constrained threads.

Native OpenClaw disables inner isolation. Its hook sets agents.defaults.workspace and any agents.entries.main.workspace to sandboxDataMount.mountPath for the Gateway, file transfer, and node. Admission requires main as the default Agent. Native workers use separate workspaces and share the Sandbox user, filesystem, process, and network. OpenShell isolates Agent revisions from other workloads. Sessions within one Agent share that boundary. Kubernetes defaults to eight native workers; runtime.nativeOpenClawSessionCapacity accepts 1 through 1024. Stopping a session releases its slot; idle workers are not retired automatically.

Kubernetes and admission requirements

Keep tenant namespaces under restricted Pod Security Admission. OCE does not create a RuntimeClass, select a node runtime, or configure PSA exemptions or API server admission flags. The supported OpenShell workload, bootstrap, and supervisor containers run non-root without added capabilities or privilege escalation. Retain approved images, ServiceAccounts, namespace ownership, and default-deny networking. A compatible node runtime and the qualification checks below remain required; omitting runtime selection does not establish runtime compatibility.

Gateway Kubernetes authority

Stock OpenShell v0.1.9 operator mode watches Sandboxes cluster-wide. Selectors filter discovery, not RBAC. Sandbox list/watch exposes Pod templates, literal values and Secret references, without granting Secret payload access.

The operator ClusterRole permits cluster-wide Sandbox and Pod mutations. The 0.1.9 Workspace Role adds Pod create/delete/list/patch/watch and Service/NetworkPolicy create/get. The 0.1.6 operator ClusterRole already granted these verbs cluster-wide. Disabling sandbox updates, namespace labels and NetworkPolicies do not limit Kubernetes permissions. OCE's legacy integration requires operator mode.

OCE controller/worker grants remain separate: Compute access, namespace-scoped policy apply and Gateway readiness, without Sandbox custom-resource permission. Do not grant wildcard tenant permissions.

Kubernetes Compute retains default-deny policies. In the development profile, provider transport grants the Agent Gateway egress only to the configured shared OpenShell peer and port and omits direct Harness ingress. Broad namespace allows can bypass this boundary. Production must instead select the separate service port required by the qualification contract below.

Compute passes provider-fenced-v1 to the provider Harness template; retain it on the Pod. This profile admits no Compute DNS, model or authentication egress; OpenShell's workload fence governs those decisions. The policy proxy opens node connections from OpenShell supervisor Pods, which carry no openclaw.dev labels; on one cluster, each Agent Gateway admits only its own Sandbox's supervisor (openshell.ai/sandbox-id). The OpenShell Gateway also needs scoped DNS/API policies. Redeploy an existing Agent to apply the profile and this scoping. See the network profile reference.

Qualification contract

Workload identity

OpenShell cannot preserve an Agent ServiceAccount and projected token. Dedicated Agents need Compute's servicePrincipalCredentials.mode: disabled or a compatible Sandbox Driver. Deployment admission rejects projected identity; saving a credential-source binding does not validate it. OpenShell may use its gateway-configured infrastructure ServiceAccount; supervisor credentials must remain inaccessible to the Agent.

Kubernetes ServiceAccount tokens cannot identify an OCE Agent across cluster trust domains. Future exchange must scope evidence to its ServicePrincipal and Agent revision; Gateway and Harness authenticate separately. See authorization.

Writable runtime state

OpenShell mounts /sandbox/.openclaw-runtime from an Agent revision's separate PVC subpath, never the PVC root. Persistent categories use separate subpaths below /sandbox/.openclaw-mounts. Exact mount paths, including OPENCLAW_NODE_STATE_DIR, use a process-created state child so atomic writes avoid symlinks and permission changes on root-owned mounts. PVC quota limits runtime storage; Agent deletion removes it.

Before opening node state, the Codex Harness and dedicated OpenClaw worker set their process-owned state root to 0700, clearing inherited setgid bits. Shared workspace directories keep their permissions. OpenClaw prepares its private children, including a control directory retained after a failed setup.

The supervisor probes the image's /tmp; native OpenClaw uses its runtime-home tmp child without changing supervisor directory permissions. Codex's container has a 1Gi ephemeral-storage limit. Operator-mode native provisioning privatizes writable PVC subpaths, keeping retained entries, in a restricted per-revision Deployment; ownership/mode checks, foreground deletion and writer termination precede Sandbox creation. It needs kubernetes.userNamespaces: false, at most one gateway.operatorWorkspaceResources ServiceAccount and the pinned Gateway's default identity, without UID/GID overrides; Agent save refuses dedicated OpenClaw otherwise. Ordinary Kubernetes Compute may use /home/node and /tmp emptyDir volumes limited to 1Gi and 64Mi.

Remaining qualification work

OpenShell's optional supervisor application listener serves HTTP and WebSocket traffic on a separate port. OCE still needs routing to the owning supervisor and application authentication. Verify a real model turn there, deny management RPCs from Agent Gateways, and reserve control-plane access for authenticated Sandbox and Credential Gateway callers.

OpenShell gateway authentication must bind each trusted control-plane caller to the requested Sandbox or Pod identity. Provider-managed files require real Kubernetes proof of their lifecycle, limits, direct-open behavior, and failures. The proxy-mediated workspace-node enrollment above requires an exact k3d proof. Missing admission, node enrollment, or gateway guarantees must fail the Agent revision instead of launching a weakened Harness.

Sandbox log reads

readSandboxLogs calls only GetSandboxLogs. The OCC gateway identity needs the sandbox:read scope and Workspace role user. OpenShell NOT_FOUND becomes RUNTIME_LOGS_SANDBOX_NOT_FOUND. See Agent logs.

Troubleshooting

  • Startup requires bundled Kubernetes Compute and an OpenShell Backend. Configure the Gateway endpoint on the Backend.
  • For a credential attachment failure, verify that the selected Backend issued the attachment and check its provider status in OpenShell.
  • For an unavailable Gateway, check Service and Pod readiness.
  • For SANDBOX_HARNESS_UNSUPPORTED, select dedicated Codex or OpenClaw.
  • OpenShell refused <method>: ... limit of durable request admissions ... reports SANDBOX_ADMISSION_LIMIT_REACHED. Raise the configured limit or, since no API resets unresolved records, inspect the Gateway database, then redeploy. Other RESOURCE_EXHAUSTED errors retry.
  • OpenShell dedicated Harness exposure requires one literal APP_TOKEN_SHA verifier. Malformed deployment or raw app-server token.
  • Codex plugin preparation failed before native WebSocket startup. Verify plugin availability for the bound Codex account and connect its app. Correct the selection or access, then redeploy. See plugin installation.
  • Provider environment is unavailable or changed during preparation with no Codex app-server: verify Unix write access to /sandbox/.openclaw-runtime/home/.codex and exclude PVC mounts below /sandbox/.openclaw-runtime. Landlock grants cannot override image ownership.

Private CAs for Gateway peers

If both pkiInitJob.enabled and certManager.enabled are false and the Gateway container does not trust the issuing CA, set:

server:
  extraEnv:
    - name: OPENSHELL_PEER_TLS_CA_FILE
      value: /etc/openshell-tls/server/ca.crt

Include the public ca.crt in the Secret named by server.tls.certSecretName. Middleware uses tls_ca_cert_path separately.

Gateway identity and removal

During stop, deletion, or credential withdrawal, check sandbox-gateway-identity for SANDBOX_GATEWAY_UNAUTHORIZED. Missing Workspace roles fail immediately. Restore the role or redeploy an externally removed Workspace. For authentication failures, check the controller token file and Gateway signing-key refresh. Workers retry transient failures within their attempt budget.

OpenShell can hide resources with NOT_FOUND. To confirm absence, the Driver reads the Workspace as the controller and rereads the resource. A delete that returns NOT_FOUND immediately after a successful read raises SANDBOX_DELETION_UNCONFIRMED. The exposure sweep logs worker.harness-exposure-withdrawal-unconfirmed and retries.

During Namespace setup or cleanup, the lifecycle adapter treats SandboxNamespaceRefusedError (PERMISSION_DENIED or UNAUTHENTICATED) as permanent. The worker records the setup refusal code. Restore gateway identity and Workspace access before retrying. Diagnostics include the method, gRPC status and validation category, and omit provider text and request values.

CreateSandbox admission failures

For CreateSandbox, worker.completed reports grpcStatus and validationCategory without resource names or supplier text.

  • 9, CALLER_DRIVER_CONFIG_DISABLED — Legacy mounts require allow_driver_config.
  • 9, PVC_ADMISSION_LABELS: Check admission labels on the namespaced PersistentVolumeClaim.
  • 9, CLASS_ADMISSION_LABELS: Check RuntimeClass or PriorityClass admission labels. For either refusal, use an approved resource or obtain owner approval before relabeling.
  • 13, RESOURCE_METADATA_FORBIDDEN: Kubernetes denied a metadata read (HTTP 403). Verify the Gateway ServiceAccount's read permission for the claim or cluster-scoped class.
  • UNKNOWN: The status alone does not identify the cause. Inspect the request configuration and Gateway diagnostics.

See Sandbox startup refusal codes.

Related documentation