Automation

Python drives the devices.
You watch every command.

ZapTerm runs your Python scripts and notebooks — and lets an AI assistant work — against the sessions you already have. Every command is typed in a real terminal tab, through the same jump hosts, vault passwords and login scripts as when you connect by hand — so nothing happens out of sight.

How it works

Your script, notebook or assistantout = sw.run("show version")decides what to do
ZapTerma real tab you can seeconnects, types, reads the output
DevicesCisco · Arista · Junos · FortiGate…SSH, Telnet or serial

The script decides, ZapTerm does

Your code never opens a connection itself. It asks ZapTerm to run a command and gets the text back; you see it happen in the tab and can take over at any moment.

Connections stay ZapTerm's job

A script opens saved sessions by name. Jump hosts, vault passwords, login scripts and host keys are handled as for any session you open yourself.

Passwords never reach your code

send_secret("Name.Password") asks ZapTerm to type a vault credential into the session. The script can't read it.

What you need: Python 3.9 or newer on the same computer. ZapTerm puts its zapterm module on the path when it runs your script, so nothing else is required — and you can use any library you have installed, such as Jinja2, pandas or ncclient.

Run a script in three steps of trust

Tools → Run Python script… picks a .py file; Tools → Script examples… opens the folder with the examples that come with ZapTerm.

The Tools menu with Run Python script, Script examples, AI assistant (MCP), Notebook connection, Automation activity, Send command list, Active tunnels and Settings.
The Run script dialog for version_audit.py with three modes: Dry run, Read-only (sending only commands that start with get or show) and Run, plus the Python interpreter to use.
Dry run

Nothing is sent or opened. Every action is listed as "would open…", "would run…", so you see exactly what the script would type on each device.

Read-only

Sessions are opened and commands starting with get or show (you can change the list) run for real; anything else is skipped and logged. The script works on real output without changing a device.

Run

Every command is sent. After a dry or read-only run the panel offers Run for real, with the same script.

ZapTerm enforces the mode, not the script: in Dry run and Read-only, a command the mode doesn't allow never reaches the device, whatever the code does. The Python field picks the interpreter, for example a virtual environment with your own libraries.

Example: software versions across vendors

Four saved sessions, four vendors. ZapTerm detects each device's platform, so the script picks the right command and pattern for it and adds a row to the summary table with report().

"""Software version of every device in a list, whatever the vendor.

Run it from Tools -> Run Python script... in Read-only mode: it only sends
`show` / `get` commands, so a real run changes nothing either.
"""

import re

import zapterm

DEVICES = ["core-rtr-01", "spine-01", "edge-mx-01", "fw-hq-01"]  # saved sessions
CLOSE_TABS = False  # keep each device's tab open to look at it afterwards

# Which command shows the version, and how to find it, per detected platform.
VERSION = {
    "cisco_ios": ("show version", r"Version ([\w.()]+)"),
    "arista_eos": ("show version", r"Software image version: (\S+)"),
    "juniper": ("show version", r"Junos: (\S+)"),
    "fortigate": ("get system status", r"Version: (.+)"),
}

for name in DEVICES:
    try:
        s = zapterm.open(name)
        command, pattern = VERSION.get(s.platform, ("show version", r"[Vv]ersion:? (\S+)"))
        out = s.run(command)
        found = re.search(pattern, out)
        if zapterm.dry_run:
            zapterm.report(name, "DRY RUN", f"would run: {command}")
        elif found:
            zapterm.report(name, "OK", f"{s.platform or 'unknown'} · {found.group(1).strip()}")
        else:
            zapterm.report(name, "NO VERSION", f"nothing matched in `{command}`")
        if CLOSE_TABS:
            s.close()
    except zapterm.Error as e:  # a device that fails doesn't stop the others
        zapterm.report(name, "FAILED", str(e))
ZapTerm after running version_audit.py read-only: a tab per device, the FortiGate's get system status output, and the script panel with a row per device: core-rtr-01 cisco_ios 17.12.3, spine-01 arista_eos 4.32.2F, edge-mx-01 juniper 23.4R2.13, fw-hq-01 fortigate v7.4.5.
Read-only run: each device's tab stays open and the panel shows the summary and the log.

Example: a Jinja2 template on a set of devices

One row per device in a CSV file, one template, rendered per device and typed line by line. Jinja2 isn't part of ZapTerm: install it in the Python you run the script with (pip install jinja2).

ntp.j2

configure terminal
ntp server {{ ntp_primary }} prefer
ntp server {{ ntp_secondary }}
{% for vlan in vlans.split() -%}
interface Vlan{{ vlan }}
 ip helper-address {{ dhcp_relay }}
{% endfor -%}
end

devices.csv

device,ntp_primary,ntp_secondary,dhcp_relay,vlans
core-rtr-01,10.10.0.123,10.20.0.123,10.10.5.10,10 20
spine-01,10.10.0.123,10.20.0.123,10.10.5.10,30

push_template.py

"""Render a Jinja2 template per device from a CSV file and send it.

devices.csv has one row per device (the `device` column is the saved
session's name) and one column per template variable. ntp.j2 is the template.

Needs Jinja2 in the Python ZapTerm uses:  pip install jinja2
Always start with Dry run: it lists, per device, exactly what would be typed.
"""

import csv
from pathlib import Path

from jinja2 import Environment, FileSystemLoader, StrictUndefined

import zapterm

HERE = Path(__file__).parent
env = Environment(loader=FileSystemLoader(HERE), undefined=StrictUndefined)
template = env.get_template("ntp.j2")

with open(HERE / "devices.csv", newline="") as f:
    rows = list(csv.DictReader(f))

if not zapterm.confirm(f"Send ntp.j2 to {len(rows)} device(s)?"):
    raise SystemExit("Cancelled.")

for row in rows:
    name = row["device"]
    lines = [l for l in template.render(**row).splitlines() if l.strip()]
    try:
        s = zapterm.open(name)
        for line in lines:
            out = s.run(line)
            if out.lstrip().startswith("%"):  # Cisco-style error
                raise zapterm.Error(f"{line!r}: {out.strip()}")
        zapterm.report(name, "DRY RUN" if zapterm.dry_run else "OK", f"{len(lines)} lines")
        s.close()
    except zapterm.Error as e:
        zapterm.report(name, "FAILED", str(e))
The script panel after a dry run of push_template.py: core-rtr-01 DRY RUN 8 lines, spine-01 DRY RUN 6 lines, and the log listing every rendered line it would run on each device.
Dry run: the rendered configuration for every device, before anything is sent.

A device that answers a line with a Cisco-style error (output starting with %) stops there and is reported as FAILED; the others carry on. Check the rendered lines in Dry run, the device state in Read-only, then send it.

Notebooks: explore first, script later

A script runs top to bottom. While you write one you want the opposite: run one command, look at what the device really prints, write the parsing against it, try again. A Jupyter notebook in JupyterLab or VS Code does that, driving ZapTerm's tabs with the same zapterm module.

  1. Tools → Notebook connection… The panel shows the two lines a notebook needs; Copy puts them on the clipboard. It is local to your computer, off by default, and turns itself off after 60 minutes without notebook calls.
  2. In the notebook, import zapterm and zapterm.connect(). Then zapterm.tab("name") for an open tab or zapterm.open("saved session").
  3. Run cells. Each run() is typed in the tab and its output comes back to the cell. Variables stay between cells, so you re-run only the parsing you are fixing.
The Notebook connection panel: waiting for a notebook, what a notebook may send set to Read-only (the other levels are Ask me first and No questions), the sys.path and import lines to paste into the notebook, and an empty list of what was sent since it was turned on.
A JupyterLab notebook: connect to ZapTerm, list its tabs, run show ip interface brief on core-rtr-01 and parse the interfaces that are down: Vlan1, TwentyFiveGigE1/0/3, HundredGigE1/0/26.
The notebook…
ZapTerm at the same time: the core-rtr-01 tab shows show ip interface brief typed by the notebook, and the panel says Connected · Python, Read-only, and lists the session it opened and the command it sent.
…and ZapTerm at the same moment.

A notebook starts Read-only: only get and show reach the device. Move the panel's control to Ask me first when you mean to change something: ZapTerm then shows each other command and waits for your Yes. Bigger changes belong in a script you've dry-run. When the cells work, copy them into a .py file, loop over zapterm.sessions(folder) and add report() lines.

An AI assistant, on your terms

Ask in plain words — "which interfaces are down on core-rtr-01?", "compare the HA state of the two firewalls" — and an assistant that speaks MCP (the Model Context Protocol) runs the commands through ZapTerm and reads the answers. It gets the same deal as a script: real tabs you can watch, and rules that ZapTerm enforces, whatever the assistant decides.

  1. Tools → AI assistant (MCP)… The panel shows the configuration to paste into your assistant (Claude Desktop, or any other MCP client that can start a local server); Copy puts it on the clipboard. It points at zapterm_mcp.py, plain Python with no packages to install.
  2. Quit the assistant completely and open it again, so it reads the configuration.
  3. Ask it something about a device. The panel shows who connected, by name, and every command as it happens.
ZapTerm with an AI assistant connected in Read-only. The fw-hq-01 tab shows get system status typed by the assistant; the panel lists what it sent since it was turned on — open session fw-hq-01, get system status, get system performance status, show ip bgp summary and show interfaces status on core-rtr-01 — and marks 'configure terminal' as blocked.
Read-only

The default. Only commands starting with get or show (the same list as for scripts, set in the Run script dialog) reach a device. Anything else is refused, and the assistant is told it was not sent.

Ask me first

Display commands go straight through. Before any other command, ZapTerm shows it to you, says who is asking, and waits for your Yes.

No questions

Every command is sent as it comes. Only for work you would hand over without watching.

What it can do

List open tabs and saved sessions, open a saved session, run a command in a tab and read its output, and ask which level is on. Five tools, nothing else.

What it can't

See or type a password: ZapTerm logs in from its vault, and no tool exposes one. Nor chain commands past the rules — a line with ;, |, &, <, >, a backtick or $( is not a display command.

One at a time, only on this computer

The connection is local, off until you turn it on, accepts one client, and turns itself off after 60 minutes without calls. A notebook is refused while the assistant's entry is on, and the other way round.

What leaves your computer: ZapTerm sends nothing anywhere. But what your devices print in answer to the assistant's commands goes to that assistant, and so to its provider — think about which devices and which commands you let it reach. Passwords are not part of it.

A record of everything that was sent

Every command a script, a notebook or an assistant sent — or tried to send — is written to a plain text file on your computer, one line per event: when, who, on which device, the command, and what became of it. Tools → Automation activity… shows it with counters, filters and search.

Automation activity: 9 actions, 8 sent and 1 blocked, with the last 14 days. One card per visit: the assistant's, with the sessions it opened, the commands it ran on fw-hq-01 and core-rtr-01 and 'configure terminal' blocked by Read-only; and a notebook's, with show ip interface brief.

What became of each command

Sent, blocked by Read-only, declined by you, approved and sent, no prompt in time, or an error — with how long it took.

Commands, not output

Only the command line is kept, never what the device printed (session logging does that). Passwords that ZapTerm recognises in a command are masked: set password ******.

Yours to keep or delete

One file per month in the logs folder, tab-separated, readable in any editor or spreadsheet. Open file and Folder take you there.

The zapterm module at a glance

CallWhat it does
zapterm.session()The tab that was focused when the script started.
zapterm.open(name)Open a saved session in a new tab and wait until it is connected.
zapterm.tab(name) / tabs()A tab already open, by name / all open tabs.
zapterm.sessions(folder)Names of the saved sessions, or only those in a folder and its sub-folders.
s.run(cmd, timeout=30)Type a command, wait for the prompt, return the output. With strict=True it raises when Read-only keeps the command from being sent.
s.send(text) / s.expect(pattern)Type without waiting / wait for a text or regex to appear.
s.send_secret("Name.Password")Type a vault credential; the script never sees it.
s.poll(cmd, until, every, max)Repeat a command until a condition holds or time runs out.
s.platform / s.close()Detected platform ("cisco_ios", "fortigate"…) / close the tab.
zapterm.report(target, status, detail)Add a row to the summary table.
zapterm.confirm(msg) / log(…) / sleep(s)Ask yes/no in ZapTerm / write to the panel / wait (skipped in Dry run).
zapterm.dry_run / read_onlyTrue when the script runs in that mode.
zapterm.connect()From a notebook or a Python prompt: connect to the running ZapTerm.