02 Guide

Working with SageCode

The few ideas every command shares, recipes for the jobs you'll do most (running scripts, building workflows, webhooks, schedules and CI), and how to work with Sage.

Naming resources

Every command that acts on something (a workflow, script, run, trigger, vault, server or key) takes either its name or its id.

  • Names are matched without regard to case. sagex show workflow deploy finds “Deploy”.
  • Script names include their extension: deploy.sh, migrate.py.
  • Runs are usually named by id, and the first few characters are enough: sagex show run 46a2.
  • If a name matches more than one thing, SageCode lists the matches with their ids so you can pick. For a server or key whose name exists in more than one vault, add --vault.

Your workspace

SageCode keeps local files in one folder, your workspace. It's the current directory unless you choose one, and it's a good thing to keep in git.

terminal
❯ sagex workspace set ~/infraWorkspace set to: /home/you/infra
FolderWhat's in it
workflows/Workflow JSON, from new, copy or for push
scripts/Script files, from new, copy or for push
logs/script/<id>/Saved by run script
logs/workflow/<run id>/Run metadata and logs: saved by run workflow, rerun, watch, trigger fire and trigger watch, and by copy run

Commands that read a local file accept a path, or just a name inside the matching folder: sagex push script deploy finds scripts/deploy.sh. Relative paths always start from the workspace, never the folder you're in, so it doesn't matter where you run a command. Once you've set a workspace, the terminal app opens there too.

Output and exit codes

  • Tables by default, JSON on request. Every list and most show commands take --json, ready for jq.
  • Script output on stdout, everything else on stderr. During a live run, SageCode's own progress lines go to stderr, so sagex run script report.sh -s web-1 > report.txt captures only what the script printed.
  • Exit codes you can build on. run script exits with the script's own exit code. run workflow exits 0 when the run succeeds, 1 when it fails, and 130 when you cancel it or detach.

During a live run, Ctrl+C stops it. Press it again to detach: the run carries on, and sagex show run <id> checks on it later.

Run a script on a server

Pick a script and a server from your vault. SageCode streams the output live, line by line, and saves a copy of the logs in your workspace.

terminal
❯ sagex run script disk_check.sh --server web-1 -p THRESHOLD=90
  • A script's inputs are its {{NAME}} markers. Each value comes from --param, else the script's saved default, else a prompt.
  • Secret inputs are always asked for at a hidden prompt, never taken as a flag.
  • SageCode connects with the key attached to the server. Use --key to pick a different key from the same vault.
  • Add --no-log to skip saving the logs locally.

Build a workflow from files

Scaffold a workflow, fill it in with the snippets SageCode gives you, preview it, then push it to the server.

terminal
❯ sagex new workflow "Disk Check" # workflows/Disk_Check.json❯ sagex list script # ids for the nodes you'll add❯ sagex syntax script # JSON for a script node❯ sagex render workflow --file "Disk Check" # preview the flow❯ sagex push workflow "Disk Check" # create it on the server
  • The new file explains every field in a _doc block, which is never sent to the server.
  • The first push creates the workflow and writes its id back into the file. Later pushes update it, after asking.
  • sagex syntax prints snippets for trigger, script, email, decision, edge and decision-edge.
  • If the file's id is stale (say, the workflow was deleted), push workflow --new creates a fresh one.

Scripts work the same way: sagex new script disk_check --lang shell, then sagex push script disk_check. When you update a script, SageCode shows a diff of the server copy against yours before asking.

Expose a webhook

An HTTP trigger gives a workflow a URL that other systems can call. SageCode creates it, shows you how to call it, and can call it exactly as an outside caller would.

terminal
❯ sagex trigger create Deploy -t http # prints the secret once❯ sagex trigger invoke Deploy # URL, headers, body and a curl❯ sagex trigger fire Deploy # call it now, then follow the run❯ sagex trigger poll Deploy --watch # what a caller sees

The secret is shown once. Store it straight away, in your CI provider's secrets for example. Lost it? sagex trigger regenerate Deploy issues a new one at the same URL, and the old one stops working.

Every call needs two headers: X-Trigger-Secret and a unique Idempotency-Key. Repeating a key returns the run it started instead of starting another, so retries are safe. Parameter values go in inputs, keyed by parameter id (shown in sagex show workflow Deploy --json):

calling the webhook
curl -X POST "$DEPLOY_WEBHOOK_URL" \ -H "X-Trigger-Secret: $DEPLOY_WEBHOOK_SECRET" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d '{"inputs": {"param-1": "1.4.2"}}'# 202 → { workflow_run_id, status, polling_url }

Schedule a job

terminal
❯ sagex trigger create Backup -t schedule --cron "0 2 * * *"❯ sagex trigger watch Backup # count down to the next run, then follow it❯ sagex trigger fire Backup # run it now, through the scheduler
  • Cron expressions have five fields and run in UTC. After saving, SageCode shows the next runs in UTC and your local time.
  • Scheduled runs have nobody to ask for input, so every parameter needs a saved value. SageCode warns you if one doesn't have one.
  • A firing is skipped if the previous scheduled run of the same workflow is still going. trigger watch tells you when that happens.
  • sagex trigger disable Backup pauses a schedule without deleting it; enable resumes it.

Unlike classic cron, a day of the month and a day of the week in the same expression must both match: 0 9 1 * 5 runs only on a Friday that's also the 1st. SageCode words its description to match.

Run from CI

In a pipeline, give SageCode its key through SAGEX_API_KEY and run a workflow. The job's exit code follows the run, so a failed deploy fails the build. Here's a GitHub Actions step:

.github/workflows/deploy.yml
jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/setup-python@v5 with: { python-version: "3.12" } - run: pip install sagex-cli - name: Deploy env: SAGEX_API_KEY: ${{ secrets.SAGEX_API_KEY }} run: sagex run workflow "Deploy Production" -p VERSION=${{ github.sha }} --no-log
  • A pipeline can't answer prompts, so every parameter needs a value, either saved in the workflow or passed with --param.
  • Secret parameters must be saved in the workflow. SageCode won't take a secret as a flag, even in CI.
  • Prefer not to install anything? Call the workflow's webhook with curl, using your commit SHA as the Idempotency-Key.

Manage the vault

Vaults hold the servers your scripts run on and the keys that log in to them.

terminal
❯ sagex create vault prod❯ sagex create key deploy-key --vault prod -t ssh --key-file ~/.ssh/id_ed25519❯ sagex create server web-1 --vault prod --host 10.0.0.12 -m ssh --key deploy-key❯ sagex update key deploy-key --set-passphrase
  • Key types are username_password, ssh_key and certificate. Passwords and passphrases are typed at hidden prompts; SSH keys and certificates come from a file you point to, or - to paste.
  • Servers connect over ssh (port 22 by default) or winrm (5985).
  • sagex show key deploy-key keeps the secret hidden. Add --reveal to see it, after confirming.
  • Deleting a vault deletes everything in it, so SageCode asks you to type the vault's name first.

Runs: look back, follow, repeat

terminal
❯ sagex list run --limit 10❯ sagex show run 46a2 --logs # status, each node, and its output❯ sagex watch 46a2 # follow a run that's already going❯ sagex rerun 46a2 # run it again with the same inputs❯ sagex cancel 46a2 # stop a queued or running run❯ sagex copy run --since 7days # into logs/workflow/ in your workspace

watch works for a run started anywhere (the web app, a trigger, Sage); Ctrl+C stops watching and leaves the run going. rerun asks again for any secrets the earlier run was given, since Autosage keeps them only masked. Run logs are kept for 90 days. copy run --since takes 1day, 7days, 1month or all.

The terminal app

Run sagex with no arguments to open the full-screen app. Your resources are on the left; the right side is a terminal-style transcript.

  • Start a line with ! to run a command, such as !sagex run workflow Deploy or !git status. Workflow runs draw a live graph as they go.
  • F3 switches the left panel between your server resources and your local workspace, where you can also change the workspace folder.
  • F2 switches the shell your commands run in. On Windows it cycles PowerShell, cmd and WSL; elsewhere bash and sh.
  • Esc stops the running command, ↑ ↓ recall earlier ones, F5 refreshes and Ctrl Q quits.
  • Anything you type without ! goes to Sage.

Ask Sage

Sage is your Autosage assistant, built into the terminal app. Type a question without ! and the answer streams into the transcript. Esc stops it.

sagex · Sage
you why did the last Deploy run fail?you write a script that checks disk space and alerts above 90%you rerun Nightly Backup with RETENTION=14
  • Ask about what you just ran. Your next question carries the end of the last ! command's output (obvious secrets masked), so "why did that fail?" just works.
  • It looks things up itself. Sage runs read-only commands like list, show and render, and reads any command's help. Each call shows as a card with the exact command and its output; click a finished card to expand it.
  • It asks before changing anything. Runs, creates, updates, deletes and pushes show as an approval card: a one-line description and the exact command. Press y to run it once, a to allow that command on that resource for the rest of the session, or n to decline. Deletes always ask.
  • Files and shell, with your approval. Sage reads, writes and edits files in your workspace (it shows the new file or a diff first) and runs shell commands in your current shell. It never touches files outside the workspace or ones that usually hold secrets, like .env, keys or .ssh.
TypeTo
/permissionsSee what you've allowed for this session; /permissions revoke <n> or revoke all takes it back
/sessionsList your saved conversations; /sessions <n> reopens one, /sessions delete <n> deletes it
/newStart a fresh conversation
/modelList your models and switch: /model <n or name>, or /model free
/usageRequests and tokens today, over 7 days and all time, with models and devices

Conversations are saved as you go, and your latest 100 are kept. Long tool output and file contents are trimmed before saving, so your files' contents aren't stored. The "Sage Today" block at the bottom of the left panel shows today's requests and tokens, the model in use and the free requests left.

Sage can never sign in, create or change vault keys or model keys, read a secret, or use --reveal. It can't type into prompts either: a run that needs a password typed at a hidden prompt is handed back to you to run with !.

Use your own model

Sage answers with Autosage's free models, which share a daily allowance with Autobot on the web. To use a model with your own provider API key instead, add it and select it:

terminal
❯ sagex create model "My Claude" --provider anthropic --model claude-sonnet-4-5 --useAPI key (hidden):✓ Added model My Claude · anthropic/claude-sonnet-4-5✓ Sage now answers with My Claude · anthropic/claude-sonnet-4-5
  • Providers: gemini, groq, openrouter, anthropic, openai, azure_openai (add --api-version), nvidia_nim and custom (any LiteLLM-compatible endpoint, with --base-url).
  • The API key is typed at a hidden prompt, or read from a file with --key-file. Never as a flag. It's stored encrypted on Autosage and never shown again. Inside the terminal app, use --key-file, since ! commands can't show a hidden prompt.
  • sagex use model <name> switches, and sagex use model --free goes back to the free models. list, show, update (--new-key replaces the key), rename and delete model manage them.
  • These are the same models as Autobot's Customize panel on the web, and the choice applies to both.