Computers

Run a command

Run a command or open an interactive shell inside a computer

You need the CLI installed and signed in and a selected workspace where you have the admin or editor role. Use the demo computer from Create a computer, with an image that includes sh.

Check the computer

nevia status demo

The state must be ready, with no pending transition. If the computer is sleeping, wake it first. Exec does not wake a computer.

Run the command

Print a message inside the computer's primary container:

nevia exec demo -- sh -c 'echo hello'

You should see:

hello

Everything after -- runs inside the computer. Exec does not start a shell, so wrap the command in sh -c when you need shell syntax.

The CLI streams the command's output and exits with its status. Check the exit code right after the command:

echo $?

0 means the command succeeded.

Wait for the command to finish before you sleep, checkpoint or delete the computer. Each of those can interrupt an exec session. See Computer lifecycle states.

nevia exec lists the command options. The exec API reference covers request limits and errors.

Set environment variables

Each run gets the computer's stored env, with secrets and variables at their current values. Add -e KEY=value to set or override a variable for one run:

nevia exec demo -e LOG_LEVEL=debug -- ./run.sh

Use -e secrets.NAME or -e variables.NAME to take a value from the workspace. Nevia resolves it on each run. For the full rules, see Computer environment variables. To manage the values, see Give computers secrets and variables.

Interactive execution

Open a shell inside the computer from your local terminal:

nevia exec demo

With no command, Nevia opens the computer's shell and allocates a terminal for you. Type a few commands:

echo hello
pwd

You see hello and the working directory inside the computer. Run exit to close the shell and return to your local terminal.

To run a specific program with a terminal, put it after --:

nevia exec demo -t -- sh

-t enables interactive input and forwards terminal resizes. It needs a local terminal for input and output. A shell opened with no command requests one on its own. To stream input without a terminal, use -i alone.

Each nevia exec -i or -t starts a new shell with the same env as one-shot exec. See Interactive sessions for what a session URL can reach.

Sessions expire after one hour. Set another duration, up to 12 hours, with --ttl:

nevia exec demo --ttl 2h

On this page