start-command 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -122,6 +122,40 @@ jobs:
122
122
  - name: Run tests
123
123
  run: bun test
124
124
 
125
+ # SSH Integration Tests - Linux only (most reliable for SSH testing)
126
+ - name: Setup SSH server for integration tests (Linux)
127
+ if: runner.os == 'Linux'
128
+ run: |
129
+ # Install openssh-server if not present
130
+ sudo apt-get install -y openssh-server
131
+
132
+ # Start SSH service
133
+ sudo systemctl start ssh
134
+
135
+ # Generate SSH key without passphrase for testing
136
+ ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N "" -C "ci-test-key"
137
+
138
+ # Add the public key to authorized_keys for passwordless login
139
+ cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys
140
+ chmod 600 ~/.ssh/authorized_keys
141
+
142
+ # Configure SSH to accept localhost connections without prompts
143
+ mkdir -p ~/.ssh
144
+ cat >> ~/.ssh/config << 'EOF'
145
+ Host localhost
146
+ StrictHostKeyChecking no
147
+ UserKnownHostsFile /dev/null
148
+ LogLevel ERROR
149
+ EOF
150
+ chmod 600 ~/.ssh/config
151
+
152
+ # Test SSH connectivity
153
+ ssh localhost "echo 'SSH connection successful'"
154
+
155
+ - name: Run SSH integration tests (Linux)
156
+ if: runner.os == 'Linux'
157
+ run: bun test test/ssh-integration.test.js
158
+
125
159
  # Release - only runs on main after tests pass (for push events)
126
160
  release:
127
161
  name: Release
package/CHANGELOG.md CHANGED
@@ -1,5 +1,51 @@
1
1
  # start-command
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 1240a29: Add SSH isolation support for remote command execution.
8
+ - Implements SSH backend for executing commands on remote servers via SSH, similar to screen/tmux/docker isolation
9
+ - Uses `--endpoint` option to specify SSH target (e.g., `--endpoint user@remote.server`)
10
+ - Supports both attached (interactive) and detached (background) modes
11
+ - Includes comprehensive SSH integration tests in CI with a local SSH server
12
+
13
+ ## 0.10.0
14
+
15
+ ### Minor Changes
16
+
17
+ - 8ea5659: Add user isolation support with --isolated-user and --keep-user options
18
+
19
+ Implements user isolation that creates a new isolated user to run commands:
20
+
21
+ ## --isolated-user option (create isolated user with same permissions)
22
+ - Add --isolated-user, -u option to create a new isolated user automatically
23
+ - New user inherits group memberships from current user (sudo, docker, wheel, etc.)
24
+ - User is automatically deleted after command completes (unless --keep-user)
25
+ - Works with screen and tmux isolation backends (not docker)
26
+ - Optional custom username via --isolated-user=myname or -u myname
27
+ - For screen/tmux: Wraps commands with sudo -n -u <user>
28
+ - Requires sudo NOPASSWD configuration for useradd/userdel/sudo
29
+
30
+ ## --keep-user option
31
+ - Add --keep-user option to prevent user deletion after command completes
32
+ - Useful when you need to inspect files created during execution
33
+ - User must be manually deleted with: sudo userdel -r <username>
34
+
35
+ ## Other improvements
36
+ - Add comprehensive tests for user isolation
37
+ - Update documentation with user isolation examples
38
+ - Integrate --keep-alive and --auto-remove-docker-container from main branch
39
+
40
+ Usage:
41
+ - $ --isolated-user -- npm test # Auto-generated username, auto-deleted
42
+ - $ --isolated-user myrunner -- npm start # Custom username
43
+ - $ -u myrunner -- npm start # Short form
44
+ - $ --isolated screen --isolated-user -- npm test # Combine with process isolation
45
+ - $ --isolated-user --keep-user -- npm test # Keep user after completion
46
+
47
+ Note: User isolation requires sudo NOPASSWD configuration.
48
+
3
49
  ## 0.9.0
4
50
 
5
51
  ### Minor Changes
package/README.md CHANGED
@@ -136,7 +136,7 @@ Issue created: https://github.com/owner/some-npm-tool/issues/42
136
136
 
137
137
  ### Process Isolation
138
138
 
139
- Run commands in isolated environments using terminal multiplexers or containers:
139
+ Run commands in isolated environments using terminal multiplexers, containers, or remote servers:
140
140
 
141
141
  ```bash
142
142
  # Run in tmux (attached by default)
@@ -148,29 +148,74 @@ $ --isolated screen --detached -- bun start
148
148
  # Run in docker container
149
149
  $ --isolated docker --image oven/bun:latest -- bun install
150
150
 
151
+ # Run on remote server via SSH
152
+ $ --isolated ssh --endpoint user@remote.server -- npm test
153
+
151
154
  # Short form with custom session name
152
155
  $ -i tmux -s my-session -d bun start
153
156
  ```
154
157
 
158
+ ### User Isolation
159
+
160
+ Create a new isolated user with the same group permissions as your current user to run commands in complete isolation:
161
+
162
+ ```bash
163
+ # Create an isolated user with same permissions and run command
164
+ $ --isolated-user -- npm test
165
+
166
+ # Specify custom username for the isolated user
167
+ $ --isolated-user myrunner -- npm start
168
+ $ -u myrunner -- npm start
169
+
170
+ # Combine with process isolation (screen or tmux)
171
+ $ --isolated screen --isolated-user -- npm test
172
+
173
+ # Keep the user after command completes (don't delete)
174
+ $ --isolated-user --keep-user -- npm start
175
+
176
+ # The isolated user inherits your group memberships:
177
+ # - sudo group (if you have it)
178
+ # - docker group (if you have it)
179
+ # - wheel, admin, and other privileged groups
180
+ ```
181
+
182
+ The `--isolated-user` option:
183
+
184
+ - Creates a new system user with the same group memberships as your current user
185
+ - Runs the command as that user
186
+ - Automatically deletes the user after the command completes (unless `--keep-user` is specified)
187
+ - Requires sudo access without password (NOPASSWD configuration)
188
+ - Works with screen and tmux isolation backends (not docker)
189
+
190
+ This is useful for:
191
+
192
+ - Running untrusted code in isolation
193
+ - Testing with a clean user environment
194
+ - Ensuring commands don't affect your user's files
195
+
155
196
  #### Supported Backends
156
197
 
157
- | Backend | Description | Installation |
158
- | -------- | -------------------------------------- | ---------------------------------------------------------- |
159
- | `screen` | GNU Screen terminal multiplexer | `apt install screen` / `brew install screen` |
160
- | `tmux` | Modern terminal multiplexer | `apt install tmux` / `brew install tmux` |
161
- | `docker` | Container isolation (requires --image) | [Docker Installation](https://docs.docker.com/get-docker/) |
198
+ | Backend | Description | Installation |
199
+ | -------- | ---------------------------------------------- | ---------------------------------------------------------- |
200
+ | `screen` | GNU Screen terminal multiplexer | `apt install screen` / `brew install screen` |
201
+ | `tmux` | Modern terminal multiplexer | `apt install tmux` / `brew install tmux` |
202
+ | `docker` | Container isolation (requires --image) | [Docker Installation](https://docs.docker.com/get-docker/) |
203
+ | `ssh` | Remote execution via SSH (requires --endpoint) | `apt install openssh-client` / `brew install openssh` |
162
204
 
163
205
  #### Isolation Options
164
206
 
165
- | Option | Description |
166
- | -------------------------------- | ----------------------------------------------------- |
167
- | `--isolated, -i` | Isolation backend (screen, tmux, docker) |
168
- | `--attached, -a` | Run in attached/foreground mode (default) |
169
- | `--detached, -d` | Run in detached/background mode |
170
- | `--session, -s` | Custom session/container name |
171
- | `--image` | Docker image (required for docker isolation) |
172
- | `--keep-alive, -k` | Keep session alive after command completes |
173
- | `--auto-remove-docker-container` | Auto-remove docker container after exit (docker only) |
207
+ | Option | Description |
208
+ | -------------------------------- | --------------------------------------------------------- |
209
+ | `--isolated, -i` | Isolation backend (screen, tmux, docker, ssh) |
210
+ | `--attached, -a` | Run in attached/foreground mode (default) |
211
+ | `--detached, -d` | Run in detached/background mode |
212
+ | `--session, -s` | Custom session/container name |
213
+ | `--image` | Docker image (required for docker isolation) |
214
+ | `--endpoint` | SSH endpoint (required for ssh, e.g., user@host) |
215
+ | `--isolated-user, -u [name]` | Create isolated user with same permissions (screen/tmux) |
216
+ | `--keep-user` | Keep isolated user after command completes (don't delete) |
217
+ | `--keep-alive, -k` | Keep session alive after command completes |
218
+ | `--auto-remove-docker-container` | Auto-remove docker container after exit (docker only) |
174
219
 
175
220
  **Note:** Using both `--attached` and `--detached` together will result in an error - you must choose one mode.
176
221
 
package/REQUIREMENTS.md CHANGED
@@ -142,6 +142,8 @@ Support two patterns for passing wrapper options:
142
142
  - `--detached, -d`: Run in detached/background mode
143
143
  - `--session, -s <name>`: Custom session name
144
144
  - `--image <image>`: Docker image (required for docker backend)
145
+ - `--isolated-user, -u [username]`: Create new isolated user with same group permissions as current user
146
+ - `--keep-user`: Keep isolated user after command completes (don't delete)
145
147
  - `--keep-alive, -k`: Keep isolation environment alive after command exits (disabled by default)
146
148
  - `--auto-remove-docker-container`: Automatically remove docker container after exit (disabled by default, only valid with --isolated docker)
147
149
 
@@ -157,7 +159,50 @@ Support two patterns for passing wrapper options:
157
159
  - **Detached mode**: Command runs in background, session info displayed for reattachment
158
160
  - **Conflict handling**: If both --attached and --detached are specified, show error asking user to choose one
159
161
 
160
- #### 6.5 Auto-Exit Behavior
162
+ #### 6.5 User Isolation
163
+
164
+ - `--isolated-user, -u [username]`: Create a new isolated user with same permissions
165
+ - Creates user with same group memberships as current user (sudo, docker, wheel, etc.)
166
+ - Automatically generates username if not specified
167
+ - User is automatically deleted after command completes (unless `--keep-user` is specified)
168
+ - For screen/tmux: Wraps command with `sudo -n -u <username>`
169
+ - Requires sudo NOPASSWD for useradd/userdel commands
170
+ - Works with screen and tmux isolation (not docker)
171
+
172
+ #### 6.6 Keep User Option
173
+
174
+ - `--keep-user`: Keep the isolated user after command completes
175
+ - Only valid with `--isolated-user` option
176
+ - User must be manually deleted later with `sudo userdel -r <username>`
177
+
178
+ Example usage:
179
+
180
+ ```bash
181
+ # Create isolated user and run command (user auto-deleted after)
182
+ $ --isolated-user -- npm test
183
+
184
+ # Custom username for isolated user
185
+ $ --isolated-user myrunner -- npm start
186
+ $ -u myrunner -- npm start
187
+
188
+ # Combine with screen isolation
189
+ $ --isolated screen --isolated-user -- npm test
190
+
191
+ # Combine with tmux detached mode
192
+ $ -i tmux -d --isolated-user testuser -- npm run build
193
+
194
+ # Keep user after command completes
195
+ $ --isolated-user --keep-user -- npm test
196
+ ```
197
+
198
+ Benefits:
199
+
200
+ - Clean user environment for each run
201
+ - Inherits sudo/docker access from current user
202
+ - Files created during execution belong to isolated user
203
+ - Automatic cleanup after execution (unless --keep-user)
204
+
205
+ #### 6.7 Auto-Exit Behavior
161
206
 
162
207
  By default, all isolation environments (screen, tmux, docker) automatically exit after the target command completes execution. This ensures:
163
208
 
@@ -180,10 +225,11 @@ The `--auto-remove-docker-container` flag enables automatic removal of the conta
180
225
 
181
226
  Note: `--auto-remove-docker-container` is only valid with `--isolated docker` and is independent of the `--keep-alive` flag.
182
227
 
183
- #### 6.6 Graceful Degradation
228
+ #### 6.8 Graceful Degradation
184
229
 
185
230
  - If isolation backend is not installed, show informative error with installation instructions
186
231
  - If session creation fails, report error with details
232
+ - If sudo fails due to password requirement, command will fail with sudo error
187
233
 
188
234
  ## Configuration Options
189
235
 
@@ -0,0 +1,83 @@
1
+ # User Isolation Research
2
+
3
+ ## Issue #30: Support user isolation
4
+
5
+ ### Understanding the Requirement
6
+
7
+ Based on the issue description:
8
+
9
+ > We need to find a way to support not only isolation in screen, but also isolation by user at the same time.
10
+
11
+ And the clarification from the user:
12
+
13
+ > No, there is no way to use existing user to run the command, user isolation should mean we create user - run command using this user, after command have finished we can delete user, unless we have `--keep-user` option.
14
+
15
+ This means:
16
+
17
+ 1. Running commands in isolated environments (screen, tmux, docker) - **ALREADY IMPLEMENTED**
18
+ 2. Creating new isolated users with same permissions as current user - **IMPLEMENTED**
19
+ 3. Automatic cleanup of isolated users after command completes - **IMPLEMENTED**
20
+ 4. Option to keep the user (`--keep-user`) - **IMPLEMENTED**
21
+
22
+ ### Related Issues
23
+
24
+ - Issue #31: Support ssh isolation (execute commands on remote ssh servers)
25
+ - Issue #9: Isolation support (closed - implemented screen/tmux/docker)
26
+
27
+ ### Final Implementation
28
+
29
+ The `--isolated-user` option creates a new isolated user with the same group memberships as the current user:
30
+
31
+ ```bash
32
+ # Create isolated user and run command (user auto-deleted after)
33
+ $ --isolated-user -- npm test
34
+
35
+ # Custom username for isolated user
36
+ $ --isolated-user myrunner -- npm start
37
+ $ -u myrunner -- npm start
38
+
39
+ # Combine with screen isolation
40
+ $ --isolated screen --isolated-user -- npm test
41
+
42
+ # Combine with tmux detached mode
43
+ $ -i tmux -d --isolated-user testuser -- npm run build
44
+
45
+ # Keep user after command completes
46
+ $ --isolated-user --keep-user -- npm test
47
+ ```
48
+
49
+ ### How It Works
50
+
51
+ 1. **User Creation**
52
+ - Creates new system user with same group memberships as current user
53
+ - Inherits sudo, docker, wheel, admin, and other groups
54
+ - Uses `sudo useradd` with `-G` flag for groups
55
+
56
+ 2. **Command Execution**
57
+ - For screen/tmux: Wraps command with `sudo -n -u <user>`
58
+ - For standalone (no isolation backend): Uses `sudo -n -u <user> sh -c '<command>'`
59
+
60
+ 3. **Cleanup**
61
+ - After command completes, user is deleted with `sudo userdel -r <user>`
62
+ - Unless `--keep-user` flag is specified
63
+
64
+ ### Requirements
65
+
66
+ - `sudo` access with NOPASSWD configuration for:
67
+ - `useradd` - to create the isolated user
68
+ - `userdel` - to delete the isolated user
69
+ - `sudo -u` - to run commands as the isolated user
70
+
71
+ ### Benefits
72
+
73
+ - Clean user environment for each run
74
+ - Inherits sudo/docker access from current user
75
+ - Files created during execution belong to isolated user
76
+ - Automatic cleanup after execution (unless --keep-user)
77
+ - Prevents untrusted code from affecting your user's files
78
+
79
+ ### Limitations
80
+
81
+ - Not supported with Docker isolation (Docker has its own user isolation mechanism)
82
+ - Requires sudo NOPASSWD configuration
83
+ - Only works on Unix-like systems (Linux, macOS)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "start-command",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "Gamification of coding, execute any command with ability to auto-report issues on GitHub",
5
5
  "main": "index.js",
6
6
  "bin": {
package/src/bin/cli.js CHANGED
@@ -15,12 +15,19 @@ const {
15
15
  } = require('../lib/args-parser');
16
16
  const {
17
17
  runIsolated,
18
+ runAsIsolatedUser,
18
19
  getTimestamp,
19
20
  createLogHeader,
20
21
  createLogFooter,
21
22
  writeLogFile,
22
23
  createLogPath,
23
24
  } = require('../lib/isolation');
25
+ const {
26
+ createIsolatedUser,
27
+ deleteUser,
28
+ hasSudoAccess,
29
+ getCurrentUserGroups,
30
+ } = require('../lib/user-manager');
24
31
 
25
32
  // Configuration from environment variables
26
33
  const config = {
@@ -211,37 +218,35 @@ function getToolVersion(toolName, versionFlag, verbose = false) {
211
218
  return firstLine || null;
212
219
  }
213
220
 
214
- /**
215
- * Print usage information
216
- */
221
+ /** Print usage information */
217
222
  function printUsage() {
218
- console.log('Usage: $ [options] [--] <command> [args...]');
219
- console.log(' $ <command> [args...]');
220
- console.log('');
221
- console.log('Options:');
222
- console.log(
223
- ' --isolated, -i <environment> Run in isolated environment (screen, tmux, docker)'
224
- );
225
- console.log(' --attached, -a Run in attached mode (foreground)');
226
- console.log(' --detached, -d Run in detached mode (background)');
227
- console.log(' --session, -s <name> Session name for isolation');
228
- console.log(
229
- ' --image <image> Docker image (required for docker isolation)'
230
- );
231
- console.log(
232
- ' --keep-alive, -k Keep isolation environment alive after command exits'
233
- );
234
- console.log(
235
- ' --auto-remove-docker-container Automatically remove docker container after exit (disabled by default)'
236
- );
237
- console.log(' --version, -v Show version information');
238
- console.log('');
239
- console.log('Examples:');
240
- console.log(' $ echo "Hello World"');
241
- console.log(' $ bun test');
242
- console.log(' $ --isolated tmux -- bun start');
243
- console.log(' $ -i screen -d bun start');
244
- console.log(' $ --isolated docker --image oven/bun:latest -- bun install');
223
+ console.log(`Usage: $ [options] [--] <command> [args...]
224
+ $ <command> [args...]
225
+
226
+ Options:
227
+ --isolated, -i <env> Run in isolated environment (screen, tmux, docker, ssh)
228
+ --attached, -a Run in attached mode (foreground)
229
+ --detached, -d Run in detached mode (background)
230
+ --session, -s <name> Session name for isolation
231
+ --image <image> Docker image (required for docker isolation)
232
+ --endpoint <endpoint> SSH endpoint (required for ssh isolation, e.g., user@host)
233
+ --isolated-user, -u [name] Create isolated user with same permissions
234
+ --keep-user Keep isolated user after command completes
235
+ --keep-alive, -k Keep isolation environment alive after command exits
236
+ --auto-remove-docker-container Auto-remove docker container after exit
237
+ --version, -v Show version information
238
+
239
+ Examples:
240
+ $ echo "Hello World"
241
+ $ bun test
242
+ $ --isolated tmux -- bun start
243
+ $ -i screen -d bun start
244
+ $ --isolated docker --image oven/bun:latest -- bun install
245
+ $ --isolated ssh --endpoint user@remote.server -- ls -la
246
+ $ --isolated-user -- npm test # Create isolated user
247
+ $ -u myuser -- npm start # Custom username
248
+ $ -i screen --isolated-user -- npm test # Combine with process isolation
249
+ $ --isolated-user --keep-user -- npm start`);
245
250
  console.log('');
246
251
  console.log('Piping with $:');
247
252
  console.log(' echo "hi" | $ agent # Preferred - pipe TO $ command');
@@ -311,8 +316,8 @@ if (!config.disableSubstitutions) {
311
316
 
312
317
  // Main execution
313
318
  (async () => {
314
- // Check if running in isolation mode
315
- if (hasIsolation(wrapperOptions)) {
319
+ // Check if running in isolation mode or with user isolation
320
+ if (hasIsolation(wrapperOptions) || wrapperOptions.user) {
316
321
  await runWithIsolation(wrapperOptions, command);
317
322
  } else {
318
323
  await runDirect(command);
@@ -330,45 +335,116 @@ async function runWithIsolation(options, cmd) {
330
335
  const startTime = getTimestamp();
331
336
 
332
337
  // Create log file path
333
- const logFilePath = createLogPath(environment);
338
+ const logFilePath = createLogPath(environment || 'direct');
334
339
 
335
340
  // Get session name (will be generated by runIsolated if not provided)
336
341
  const sessionName =
337
342
  options.session ||
338
- `${environment}-${Date.now()}-${Math.random().toString(36).substring(2, 8)}`;
343
+ `${environment || 'start'}-${Date.now()}-${Math.random().toString(36).substring(2, 8)}`;
344
+
345
+ // Handle --isolated-user option: create a new user with same permissions
346
+ let createdUser = null;
347
+
348
+ if (options.user) {
349
+ // Check for sudo access
350
+ if (!hasSudoAccess()) {
351
+ console.error(
352
+ 'Error: --isolated-user requires sudo access without password.'
353
+ );
354
+ console.error(
355
+ 'Configure NOPASSWD in sudoers or run with appropriate permissions.'
356
+ );
357
+ process.exit(1);
358
+ }
359
+
360
+ // Get current user groups to show what will be inherited
361
+ const currentGroups = getCurrentUserGroups();
362
+ const importantGroups = ['sudo', 'docker', 'wheel', 'admin'].filter((g) =>
363
+ currentGroups.includes(g)
364
+ );
365
+
366
+ console.log(`[User Isolation] Creating new user with same permissions...`);
367
+ if (importantGroups.length > 0) {
368
+ console.log(
369
+ `[User Isolation] Inheriting groups: ${importantGroups.join(', ')}`
370
+ );
371
+ }
372
+
373
+ // Create the isolated user
374
+ const userResult = createIsolatedUser(options.userName);
375
+ if (!userResult.success) {
376
+ console.error(
377
+ `Error: Failed to create isolated user: ${userResult.message}`
378
+ );
379
+ process.exit(1);
380
+ }
381
+
382
+ createdUser = userResult.username;
383
+ console.log(`[User Isolation] Created user: ${createdUser}`);
384
+ if (userResult.groups && userResult.groups.length > 0) {
385
+ console.log(
386
+ `[User Isolation] User groups: ${userResult.groups.join(', ')}`
387
+ );
388
+ }
389
+ if (options.keepUser) {
390
+ console.log(`[User Isolation] User will be kept after command completes`);
391
+ }
392
+ console.log('');
393
+ }
339
394
 
340
395
  // Print start message (unified format)
341
396
  console.log(`[${startTime}] Starting: ${cmd}`);
342
397
  console.log('');
343
398
 
344
399
  // Log isolation info
345
- console.log(`[Isolation] Environment: ${environment}, Mode: ${mode}`);
400
+ if (environment) {
401
+ console.log(`[Isolation] Environment: ${environment}, Mode: ${mode}`);
402
+ }
346
403
  if (options.session) {
347
404
  console.log(`[Isolation] Session: ${options.session}`);
348
405
  }
349
406
  if (options.image) {
350
407
  console.log(`[Isolation] Image: ${options.image}`);
351
408
  }
409
+ if (options.endpoint) {
410
+ console.log(`[Isolation] Endpoint: ${options.endpoint}`);
411
+ }
412
+ if (createdUser) {
413
+ console.log(`[Isolation] User: ${createdUser} (isolated)`);
414
+ }
352
415
  console.log('');
353
416
 
354
417
  // Create log content
355
418
  let logContent = createLogHeader({
356
419
  command: cmd,
357
- environment,
420
+ environment: environment || 'direct',
358
421
  mode,
359
422
  sessionName,
360
423
  image: options.image,
424
+ user: createdUser,
361
425
  startTime,
362
426
  });
363
427
 
364
- // Run in isolation
365
- const result = await runIsolated(environment, cmd, {
366
- session: options.session,
367
- image: options.image,
368
- detached: mode === 'detached',
369
- keepAlive: options.keepAlive,
370
- autoRemoveDockerContainer: options.autoRemoveDockerContainer,
371
- });
428
+ let result;
429
+
430
+ if (environment) {
431
+ // Run in isolation backend (screen, tmux, docker, ssh)
432
+ result = await runIsolated(environment, cmd, {
433
+ session: options.session,
434
+ image: options.image,
435
+ endpoint: options.endpoint,
436
+ detached: mode === 'detached',
437
+ user: createdUser,
438
+ keepAlive: options.keepAlive,
439
+ autoRemoveDockerContainer: options.autoRemoveDockerContainer,
440
+ });
441
+ } else if (createdUser) {
442
+ // Run directly as the created user (no isolation backend)
443
+ result = await runAsIsolatedUser(cmd, createdUser);
444
+ } else {
445
+ // This shouldn't happen in isolation mode, but handle gracefully
446
+ result = { success: false, message: 'No isolation configuration provided' };
447
+ }
372
448
 
373
449
  // Get exit code
374
450
  const exitCode =
@@ -390,6 +466,23 @@ async function runWithIsolation(options, cmd) {
390
466
  console.log(`Exit code: ${exitCode}`);
391
467
  console.log(`Log saved: ${logFilePath}`);
392
468
 
469
+ // Cleanup: delete the created user if we created one (unless --keep-user)
470
+ if (createdUser && !options.keepUser) {
471
+ console.log('');
472
+ console.log(`[User Isolation] Cleaning up user: ${createdUser}`);
473
+ const deleteResult = deleteUser(createdUser, { removeHome: true });
474
+ if (deleteResult.success) {
475
+ console.log(`[User Isolation] User deleted successfully`);
476
+ } else {
477
+ console.log(`[User Isolation] Warning: ${deleteResult.message}`);
478
+ }
479
+ } else if (createdUser && options.keepUser) {
480
+ console.log('');
481
+ console.log(
482
+ `[User Isolation] Keeping user: ${createdUser} (use 'sudo userdel -r ${createdUser}' to delete)`
483
+ );
484
+ }
485
+
393
486
  process.exit(exitCode);
394
487
  }
395
488