Connect and exec
A shell with kvbox connect, scripted commands with kvbox exec.
connect
kvbox connect <name>
kvbox connect <name> -- <cmd>connect opens a shell in the box over SSH, with your terminal. A stopped box is started first, a paused one resumed, a hibernated one woken. Through a control plane the SSH session goes to the host's public address and the box's own port; your access is a short-lived SSH certificate the CLI renews on its own.
ssh, scp and VS Code
kvbox ssh-config # adds your boxes to ~/.ssh/config
kvbox ssh-config dev api # or only these (added to the ones listed already)
ssh dev.kvbox # then any ssh client reaches them
kvbox ssh-config --remove dev # takes one off the list
kvbox ssh-config --remove # takes the whole block outssh-config writes one block between # BEGIN kvbox and # END kvbox at the top of ~/.ssh/config; running it again rewrites only that block. Your boxes are <box>.kvbox, an org's box is <box>.<org>.kvbox. In VS Code, Remote-SSH: Connect to Host… lists them.
Every connection goes through kvbox, as connect does: the SSH certificate is renewed when it is about to expire, and a stopped box is started, a paused one resumed, a hibernated one woken. The list is only what VS Code shows: every box works as <box>.kvbox with or without it, a box you make later too; kvbox ssh-config <box> adds it to the list. The block names the node and kvbox it was written with: after moving either, run it again.
exec
exec is the scripted surface: one command, its exit code comes back, stdin and stdout flow through. It mirrors boxd machine exec, so scripts written for one work with the other.
kvbox exec dev -- ls /app # -- separates the box from the command
kvbox exec dev -- 'cd /app && npm test' # pipes, &&, redirects and cd work: quote them
kvbox exec dev -e API_KEY=xxx -e DEBUG=1 -- env # environment variables (-e or --env, repeatable)
kvbox exec dev --timeout 30 -- ./slow-thing # killed after 30 s, exit 124
kvbox exec dev --tty -- htop # pseudo-terminal for interactive tools
kvbox exec dev --json -- make # {"output": "...", "exit_code": N}The command's exit status is kvbox exec's exit status, so this does what it says:
kvbox exec dev -- 'test -f /app/ready' && deployStdin is forwarded whenever it is not a terminal, and its end of file reaches the command:
cat data.json | kvbox exec dev -- 'cat > /tmp/data.json'
tar -cf - ./src | kvbox exec dev -- 'tar -xf - -C /app'Copy files
kvbox cp copies between this machine and a box, scp-style. Exactly one side is <box>:<path>; a relative box path is under the box user's home. Like exec, it wakes a sleeping box and refuses a stopped one.
kvbox cp ./app.apk dev:app.apk # a file in
kvbox cp dev:report.xml . # a file out
kvbox cp -r ./tests dev:t # a directory, recursiveStart a server with exec
exec returns when the command exits and nothing it started still holds the session's output. To start a server and come back, detach it from both: its own session with setsid -f, and its own files for stdin, stdout and stderr.
kvbox exec dev -- 'cd /app; setsid -f node server.js > server.log 2>&1 < /dev/null'
kvbox exec dev -- 'curl -s localhost:3000'One shell trap to know: cd /app && node server.js > server.log 2>&1 & never returns. The & applies to the whole cd && node pair, which the shell runs as a background subshell; the redirects belong to node alone, so the subshell's output is still the session and exec waits for it. A ; instead of the &&, or redirects on the group, (cd /app && node server.js) > server.log 2>&1 &, both avoid it.
Like connect, exec resumes or wakes a sleeping box on its own.