Repository navigation
Conversation
… power off and exit with its status --run "command" runs /bin/sh -c "command" in the guest through kwtty (vm.spawn(), which retries while the guest boots, for up to 120 s), as the console's user or --user's, and in --cwd GUESTDIR when given. Once the command ends the CLI powers the guest off as root (its shutdown stops every process and leaves /data clean), or syncs and stops it if that takes more than 30 s, and exits with the command's status: 128 + N when signal N ended it, 125 when it could not be started. A panic or a trap keeps its own code. stdout carries only the command's output: the console is not shown, except on stderr when kwtty never answered. When stdin and stdout are both terminals the command gets a pty (Ctrl-] quits with 130); otherwise it gets pipes, with stdin passed on and stdout and stderr kept apart. --run is refused with --no-vsock, with --input or without a command, and --cwd without --run or with a relative path, before the kernel loads. test/cli.test.ts (pnpm test:cli) runs the CLI on the base shell and on Alpine. The --help text, the README and testing.md say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nickovs
force-pushed
the
feat/cli-run
branch
from
November 29, 2026 17:39
c0c50c3 to
9ec74ea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
--run "command"to the CLI: boot, run one command in the guest, power off, and exit with the command's status. With it, unkernel can be used from scripts and CI the waydocker runis, without the timed keystrokes--inputneeds.--cwd GUESTDIRsets the command's working directory, which pairs with--mount:Behaviour
Running. The command runs as
/bin/sh -c "command"through kwtty (vm.spawn()), as the console's user or--user's, in--cwdwhen given (kwtty's chdir). spawn() already retries while the guest boots;--rungives it 120 s instead of 30, for Debian or several CPUs on a slow host.--timeoutstill applies (124).stdio. stdout carries only the command's output: the console is not shown. When stdin and stdout are both terminals the command gets a pty (resizes follow, Ctrl-] quits with 130), as
sshdecides. Otherwise it gets pipes: stdin is passed on with its EOF, and its stdout and stderr go to the CLI's own, apart. A pty would merge them and turn\ninto\r\n.Shutdown. Once the command ends, the CLI runs
poweroffin the guest as root, so a--userwithout sudo works too. The guest's shutdown stops every process and leaves/dataclean (data-stop). If the kernel has not exited within 30 s, the CLI syncs and stops it.Exit status.
--cwdthat cannot be entered)125 is what
docker runuses for "could not start". It is apart from the command's own 1 and from 127, whichshgives for a missing command. When kwtty never answered, the last 64 KiB of the console go to stderr to show why.Refused before the kernel loads (exit 1):
--runwith--no-vsock, with--input(both want stdin) or without a command, and--cwdwithout--runor with a relative path. The console's login shell is started by the guest's init, so the host has no way to give it a working directory.--cwd /dir --run 'exec "$SHELL" -l'gives an interactive shell there.--runuses no aliases:sh -cis not interactive, so the console'sapk→sudo apkalias (kw-apk.sh) does not apply. Usesudo apk add ...or--user root.Why kwtty and not the console
Typing the command into hvc0 and reading back an
echo $?means waiting for the prompt, removing the echoed line and\r\n, and separating the output from boot messages. kwtty already returns the exit status, keeps stdout and stderr apart, and is in every image, the base shell included. The change is CLI-only: no SDK, guest or kernel changes.Tests
test/cli.test.ts(pnpm test:cli, added topnpm test) runsnode js/cli.tsin a child process on the base shell, with Alpine for the user case:kill -TERM $$→ 143, and a missing command → 127;--cwdthat does not exist → 125;--cwdin a host directory given by--mount;userby default and--user root.7 tests, about 17 s (2026-11-29, Apple M3 Max, Node 26.8.1; a base-shell
--runtakes about 2.3 s from start to exit).pnpm typecheckis clean. By hand: the pty path underscript(1)(/dev/pts/0,--size, the 80x24 default when the terminal reports 0x0),--cpus 2(worker mode), and the unchanged--inputpath.Not tested:
--runon Debian, with--data, or with--restore. The pty path has no automated test, since it needs a terminal.🤖 Generated with Claude Code