Running commands
Run bash in a workspace, carry the working directory, and stay within the limits.
POST /v1/workspaces/{id}/exec runs one command line in a workspace and answers when it's done. The reference lists every field.
curl -s -X POST "$ORIGAMI_URL/v1/workspaces/$WS/exec" \
-H "authorization: Bearer $ORIGAMI_API_KEY" \
-H 'content-type: application/json' \
-d '{"command":"grep -rn TODO src | head -20","cwd":"/workspace"}'{
"stdout": "src/app.ts:12:// TODO: retry\n",
"stderr": "",
"exitCode": 0,
"cwd": "/workspace",
"executor": "shell",
"timedOut": false,
"truncated": { "stdout": false, "stderr": false }
}A command is one shell
A command can be anything bash accepts on one call: pipes, &&, loops, functions, heredocs, several lines. Up to 100,000 characters.
cat > notes/todo.md <<'EOF'
- write the report
- send it
EOF
wc -l notes/todo.mdEach command starts a fresh shell. What it defines, such as variables, functions and aliases, is gone afterwards. What it writes under /workspace stays. See what carries over.
Keep the working directory
A command starts in /workspace, or in cwd if you pass one. The result's cwd says where it ended. To go on where the last command left off, pass it back. With the run helper from the Quickstart:
let cwd = '/workspace';
for (const command of ['mkdir -p app && cd app', 'touch index.ts', 'pwd']) {
const result = await run(command, cwd);
cwd = result.cwd;
}cwd has to be /workspace or below it.
Exit codes and errors
The HTTP status says whether the command could be run. The command's own success is in the body:
- HTTP 200 whatever the command did. A failed command has a non-zero
exitCodeand usually says why instderr. - Exit code 127 means the command doesn't exist in the shell.
- Exit code 124 with
timedOut: truemeans it ran out of time. - Exit code 126 means the shell stopped it for running too many commands. See the limits below.
- HTTP 4xx or 5xx means the command didn't run at all, such as an unknown workspace (
not_found) or a bad request (invalid_request). See Errors.
Limits
| Time | 30 seconds, and less if you send timeoutMs |
| Output | 1 MiB of stdout and 1 MiB of stderr. Beyond that it's cut, and truncated says which |
| Length of a command | 100,000 characters |
| Work | 100,000 commands in one call, loop rounds included. Beyond that the command stops with exit code 126 |
The time limit stops a command that waits, such as sleep. A command that keeps the processor busy is stopped by the work limit instead, within about two seconds.
For large output, write it to a file and fetch it with the files API:
find . -type f > /workspace/.listing.txt && wc -l < /workspace/.listing.txtSeveral commands at once
Commands on the same workspace run one after another, in the order they arrive. A second request waits until the first is done, and then sees everything it wrote. Commands on different workspaces run at the same time.
What's in the shell
The shell is an emulation of bash with its usual syntax and builtins: pipes, redirections, heredocs, cd, export, read, test and [[ ]], arithmetic, arrays and associative arrays, functions, case, command substitution, and set -euo pipefail. trap isn't supported. And these commands:
| Files | ls cat cp mv rm mkdir rmdir touch ln chmod stat find tree du readlink basename dirname mktemp file |
| Text | grep egrep fgrep rg sed awk sort uniq cut paste tr head tail wc rev nl fold expand unexpand comm join column tac strings split diff tee |
| Data | jq (JSON) yq (YAML) xan (CSV) sqlite3 html-to-markdown base64 md5sum sha1sum sha256sum od |
| Archives | tar gzip gunzip zcat |
| Other | echo printf env printenv xargs seq expr date sleep timeout time true false yes which help whoami hostname bash sh |
sqlite3 works on database files in the workspace:
sqlite3 data/app.db "create table if not exists notes(text); insert into notes values('hi'); select count(*) from notes;"Not there: network access (curl, wget), interpreters (python, node), git, package managers, and anything else that isn't on the list. help in a command prints the builtins.
Tips for agents
- Tell the agent where it is. Its files are under
/workspace, it can't install anything, and each call is a fresh shell. - Pass
cwdback, or have the agent use paths from/workspace. - Keep state in files, such as a
notes.mdthe agent reads first, rather than in variables. - Read big files in pieces with
head,tail,sed -n '100,200p'orgrep -n, so that output stays well under the limit. - Prefer one command with
&&to several calls when the steps belong together: it saves round trips.