Skip to content

Commit 0863781

Browse files
committed
feat(openshell): add workspace selection
Signed-off-by: sallyom <[email protected]>
1 parent 4f6fc38 commit 0863781

7 files changed

Lines changed: 111 additions & 6 deletions

File tree

‎docs/gateway/openshell.md‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ workspace sync mode.
2222
- `openshell` CLI on `PATH` (or a custom path via
2323
`plugins.entries.openshell.config.command`)
2424
- OpenSSH client available on the Gateway host
25+
- OpenShell `v0.0.88` or newer when configuring an OpenShell workspace
2526
- An OpenShell account with sandbox access
2627
- OpenClaw Gateway running on the host
2728

@@ -69,6 +70,15 @@ openclaw sandbox explain
6970

7071
This is the most important OpenShell decision.
7172

73+
OpenShell also has a control-plane resource named a **workspace**. That is
74+
separate from the filesystem workspace described below: it scopes sandboxes,
75+
providers, policies, inference routes, and membership. Set
76+
`plugins.entries.openshell.config.workspace` to use an existing non-default
77+
OpenShell workspace. The plugin does not create OpenShell workspaces or manage
78+
their membership. When this setting is unset, the plugin preserves the
79+
OpenShell CLI's ambient `OPENSHELL_WORKSPACE` selection, or the CLI's `default`
80+
fallback when no ambient selection exists.
81+
7282
### mirror (default)
7383

7484
`plugins.entries.openshell.config.mode: "mirror"` keeps the **local workspace
@@ -124,6 +134,7 @@ All OpenShell config lives under `plugins.entries.openshell.config`:
124134
| `from` | `string` | `"openclaw"` | Sandbox source for first-time create |
125135
| `gateway` | `string` | unset | OpenShell gateway name (top-level `--gateway`) |
126136
| `gatewayEndpoint` | `string` | unset | OpenShell gateway endpoint (top-level `--gateway-endpoint`) |
137+
| `workspace` | `string` | unset | Existing OpenShell control-plane workspace used for every CLI operation |
127138
| `policy` | `string` | unset | OpenShell policy ID for sandbox creation |
128139
| `providers` | `string[]` | `[]` | Provider names attached at sandbox creation (deduped, one `--provider` flag per entry) |
129140
| `gpu` | `boolean` | `false` | Request GPU resources (`--gpu`) |
@@ -136,6 +147,19 @@ All OpenShell config lives under `plugins.entries.openshell.config`:
136147
stay under the managed roots `/sandbox` or `/agent`; other absolute paths are
137148
rejected.
138149

150+
`workspace` must match OpenShell's current workspace-name contract: 1-19
151+
lowercase alphanumeric characters or single hyphens, with no leading,
152+
trailing, or consecutive hyphen. Create it first with
153+
`openshell workspace create --name <name>`. OpenShell rejects sandbox
154+
operations when the selected workspace does not exist or is being deleted.
155+
Set it to `"default"` to override an ambient non-default Workspace explicitly.
156+
157+
The setting applies to every OpenShell sandbox managed by this plugin instance;
158+
it cannot select different OpenShell workspaces per OpenClaw agent or session.
159+
Changing it does not migrate existing sandboxes. Delete OpenClaw's OpenShell
160+
sandboxes while the old workspace is still configured, then change the setting
161+
and restart the Gateway.
162+
139163
Sandbox-level settings (`mode`, `scope`, `workspaceAccess`) live under
140164
`agents.defaults.sandbox` like any backend. See
141165
[Sandboxing](/gateway/sandboxing) for the full matrix.
@@ -228,6 +252,7 @@ Sandbox-level settings (`mode`, `scope`, `workspaceAccess`) live under
228252
mode: "remote",
229253
gateway: "lab",
230254
gatewayEndpoint: "https://lab.example",
255+
workspace: "research",
231256
policy: "strict",
232257
},
233258
},
@@ -303,6 +328,8 @@ filesystem must permit the writes. `sandbox.docker.network`,
303328
## Current limitations
304329

305330
- Sandbox browser is not supported on the OpenShell backend.
331+
- One plugin instance uses one OpenShell workspace; per-agent or per-session
332+
OpenShell workspace selection is not supported.
306333
- `sandbox.docker.binds` does not apply to OpenShell; sandbox creation fails
307334
if binds are configured.
308335
- Docker-specific runtime knobs under `sandbox.docker.*` (other than `env`)
@@ -313,8 +340,9 @@ filesystem must permit the writes. `sandbox.docker.network`,
313340

314341
## How it works
315342

316-
1. OpenClaw runs `sandbox get` for the sandbox name (with any configured
317-
`--gateway`/`--gateway-endpoint`); if that fails it creates one with
343+
1. OpenClaw runs `sandbox get` for the sandbox name (with the selected
344+
OpenShell workspace and any configured `--gateway`/`--gateway-endpoint`); if
345+
that fails it creates one in the same OpenShell workspace with
318346
`sandbox create`, passing `--name`, `--from`, `--policy` when set, `--gpu`
319347
when enabled, `--auto-providers`/`--no-auto-providers`, and one
320348
`--provider` flag per configured provider.

‎extensions/openshell/README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ Official NVIDIA OpenShell sandbox backend for OpenClaw.
44

55
This plugin lets OpenClaw use OpenShell-managed sandboxes with mirrored local workspaces and SSH command execution.
66

7+
Configuring an OpenShell workspace requires OpenShell `v0.0.88` or newer. The
8+
plugin supports OpenShell control-plane workspaces through
9+
`plugins.entries.openshell.config.workspace`; this is separate from OpenClaw's
10+
local/remote filesystem workspace mode. The setting applies to the whole plugin
11+
instance, not individual agents or sessions. When unset, the plugin preserves
12+
the OpenShell CLI's ambient `OPENSHELL_WORKSPACE` selection, or its `default`
13+
fallback when no ambient selection exists.
14+
715
## Install
816

917
```bash

‎extensions/openshell/openclaw.plugin.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
"type": "string",
2626
"minLength": 1
2727
},
28+
"workspace": {
29+
"type": "string",
30+
"minLength": 1,
31+
"maxLength": 19,
32+
"pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
33+
},
2834
"from": {
2935
"type": "string",
3036
"minLength": 1
@@ -78,6 +84,10 @@
7884
"label": "Gateway Endpoint",
7985
"help": "Optional OpenShell gateway endpoint passed as --gateway-endpoint."
8086
},
87+
"workspace": {
88+
"label": "OpenShell Workspace",
89+
"help": "Existing OpenShell control-plane workspace for sandboxes, providers, policies, and inference routes. When unset, preserves the OpenShell CLI's ambient workspace selection."
90+
},
8191
"from": {
8292
"label": "Sandbox Source",
8393
"help": "OpenShell sandbox source for first-time create. Defaults to openclaw."

‎extensions/openshell/src/cli.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ function buildOpenShellBaseArgv(config: ResolvedOpenShellPluginConfig): string[]
2626
if (config.gatewayEndpoint) {
2727
argv.push("--gateway-endpoint", config.gatewayEndpoint);
2828
}
29+
if (config.workspace) {
30+
argv.push("--workspace", config.workspace);
31+
}
2932
return argv;
3033
}
3134

‎extensions/openshell/src/config.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe("openshell plugin config", () => {
1010
command: "openshell",
1111
gateway: undefined,
1212
gatewayEndpoint: undefined,
13+
workspace: undefined,
1314
from: "openclaw",
1415
policy: undefined,
1516
providers: [],
@@ -52,6 +53,7 @@ describe("openshell plugin config", () => {
5253
command: "openshell",
5354
gateway: undefined,
5455
gatewayEndpoint: undefined,
56+
workspace: undefined,
5557
from: "openclaw",
5658
policy: undefined,
5759
providers: [],
@@ -71,6 +73,17 @@ describe("openshell plugin config", () => {
7173
).toThrow("mode must be one of mirror, remote");
7274
});
7375

76+
it("accepts an OpenShell workspace name", () => {
77+
expect(resolveOpenShellPluginConfig({ workspace: "team-1" }).workspace).toBe("team-1");
78+
});
79+
80+
it.each(["Team", "-team", "team-", "team--one", "abcdefghijklmnopqrst"])(
81+
"rejects invalid OpenShell workspace name %s",
82+
(workspace) => {
83+
expect(() => resolveOpenShellPluginConfig({ workspace })).toThrow(/workspace must/);
84+
},
85+
);
86+
7487
it("rejects timeouts beyond Node's safe timer range", () => {
7588
expect(() =>
7689
resolveOpenShellPluginConfig({

‎extensions/openshell/src/config.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type OpenShellPluginConfig = {
1313
command?: string;
1414
gateway?: string;
1515
gatewayEndpoint?: string;
16+
workspace?: string;
1617
from?: string;
1718
policy?: string;
1819
providers?: string[];
@@ -28,6 +29,7 @@ export type ResolvedOpenShellPluginConfig = {
2829
command: string;
2930
gateway?: string;
3031
gatewayEndpoint?: string;
32+
workspace?: string;
3133
from: string;
3234
policy?: string;
3335
providers: string[];
@@ -66,11 +68,22 @@ function normalizeProviders(value: string[] | undefined): string[] {
6668
const nonEmptyTrimmedString = (message: string) =>
6769
z.string({ error: message }).trim().min(1, { error: message });
6870

71+
const openShellWorkspaceName = z
72+
.string({ error: "workspace must be a valid OpenShell workspace name" })
73+
.trim()
74+
.min(1, { error: "workspace must be a valid OpenShell workspace name" })
75+
.max(19, { error: "workspace must be at most 19 characters" })
76+
.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, {
77+
error:
78+
"workspace must contain lowercase alphanumeric characters or single hyphens and must not start or end with a hyphen",
79+
});
80+
6981
const OpenShellPluginConfigSchema = z.strictObject({
7082
mode: z.enum(["mirror", "remote"], { error: "mode must be one of mirror, remote" }).optional(),
7183
command: nonEmptyTrimmedString("command must be a non-empty string").optional(),
7284
gateway: nonEmptyTrimmedString("gateway must be a non-empty string").optional(),
7385
gatewayEndpoint: nonEmptyTrimmedString("gatewayEndpoint must be a non-empty string").optional(),
86+
workspace: openShellWorkspaceName.optional(),
7487
from: nonEmptyTrimmedString("from must be a non-empty string").optional(),
7588
policy: nonEmptyTrimmedString("policy must be a non-empty string").optional(),
7689
providers: z
@@ -155,6 +168,7 @@ export function resolveOpenShellPluginConfig(value: unknown): ResolvedOpenShellP
155168
command: DEFAULT_COMMAND,
156169
gateway: undefined,
157170
gatewayEndpoint: undefined,
171+
workspace: undefined,
158172
from: DEFAULT_SOURCE,
159173
policy: undefined,
160174
providers: [],
@@ -178,6 +192,7 @@ export function resolveOpenShellPluginConfig(value: unknown): ResolvedOpenShellP
178192
command: cfg.command ?? DEFAULT_COMMAND,
179193
gateway: cfg.gateway,
180194
gatewayEndpoint: cfg.gatewayEndpoint,
195+
workspace: cfg.workspace,
181196
from: cfg.from ?? DEFAULT_SOURCE,
182197
policy: cfg.policy,
183198
providers: normalizeProviders(cfg.providers),

‎extensions/openshell/src/openshell-core.test.ts‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ describe("openshell cli helpers", () => {
158158
command: openshellCommand,
159159
gateway: "alice",
160160
gatewayEndpoint: "http://openshell.openshell-alice.svc.cluster.local:8080",
161+
workspace: "research",
161162
}),
162163
},
163164
args: ["sandbox", "get", "demo"],
@@ -172,29 +173,54 @@ describe("openshell cli helpers", () => {
172173
"alice",
173174
"--gateway-endpoint",
174175
"http://openshell.openshell-alice.svc.cluster.local:8080",
176+
"--workspace",
177+
"research",
175178
"sandbox",
176179
"get",
177180
"demo",
178181
]);
179182
});
180183

184+
it("preserves the ambient workspace when workspace is not configured", async () => {
185+
process.env.OPENSHELL_WORKSPACE = "ambient";
186+
const openshellCommand = await makeExecutable({
187+
name: "openshell",
188+
script: ["#!/bin/sh", `printf '%s\\n' "$OPENSHELL_WORKSPACE|$*" >> "__LOG__"`, "exit 0"].join(
189+
"\n",
190+
),
191+
});
192+
193+
await runOpenShellCli({
194+
context: {
195+
sandboxName: "demo",
196+
config: resolveOpenShellPluginConfig({ command: openshellCommand }),
197+
},
198+
args: ["sandbox", "get", "demo"],
199+
});
200+
201+
await expect(fs.readFile(process.env.OPEN_SHELL_CLI_TEST_LOG as string, "utf8")).resolves.toBe(
202+
"ambient|sandbox get demo\n",
203+
);
204+
});
205+
181206
it.runIf(process.platform !== "win32")(
182-
"adds direct gateway endpoints to generated ssh proxy configs",
207+
"preserves workspace selection when adding a direct gateway endpoint",
183208
async () => {
184209
const configText = [
185-
"Host openshell-demo",
210+
"Host openshell-demo.research",
186211
" User sandbox",
187-
" ProxyCommand /usr/local/bin/openshell ssh-proxy --gateway-name alice --name demo",
212+
" ProxyCommand /usr/local/bin/openshell ssh-proxy --gateway-name alice --name demo --workspace research",
188213
"",
189214
].join("\n");
190215

191216
await expect(
192217
readOpenShellSshConfig({
193218
configText,
194219
gatewayEndpoint: "http://openshell.openshell-alice.svc.cluster.local:8080",
220+
workspace: "research",
195221
}),
196222
).resolves.toContain(
197-
"ProxyCommand /usr/local/bin/openshell ssh-proxy --gateway-name alice --name demo --server 'http://openshell.openshell-alice.svc.cluster.local:8080'",
223+
"ProxyCommand /usr/local/bin/openshell ssh-proxy --gateway-name alice --name demo --workspace research --server 'http://openshell.openshell-alice.svc.cluster.local:8080'",
198224
);
199225
},
200226
);
@@ -746,6 +772,7 @@ async function makeExecutable(params: { name: string; script: string }): Promise
746772
async function readOpenShellSshConfig(params: {
747773
configText: string;
748774
gatewayEndpoint: string;
775+
workspace?: string;
749776
}): Promise<string> {
750777
const command = await makeExecutable({
751778
name: "openshell-ssh-config",
@@ -762,6 +789,7 @@ async function readOpenShellSshConfig(params: {
762789
config: resolveOpenShellPluginConfig({
763790
command,
764791
gatewayEndpoint: params.gatewayEndpoint,
792+
workspace: params.workspace,
765793
}),
766794
},
767795
});

0 commit comments

Comments
 (0)