Network Automation

Guest Shell on IOS XE: Linux Inside Your Router

Guest Shell on IOS XE - a Linux container with Python and the cli module inside the router
In: Network Automation, CCIE

There is a full Linux environment hiding inside your router. Guest Shell is a Linux container (CentOS or a minimal distro, depending on platform) that runs on the router's own hardware, with access to the device's IOS XE CLI from inside it. You can run Python, install packages, and script the router from a shell that lives on the router - no external automation host required.

This article covers Guest Shell and on-box scripting: what it is, why it matters, and - honestly - where you can and cannot run it. It extends the complete network automation guide.

What Guest Shell is

Guest Shell runs inside IOx, Cisco's application-hosting framework on IOS XE. It gives you a Linux user space with:

  • Python pre-installed, so you can write scripts that run on the router itself.
  • The cli module - a Python library that lets your script issue IOS commands and get the output back, from inside the container.
  • Package management - install libraries with pip, subject to the container's constraints.
  • Network access through the router's management, so the script can reach external services.

The point is autonomy. A script in Guest Shell runs on the device, reacts to local events, and needs no external server. Combine it with EEM (which can launch a Guest Shell script on a trigger) and the router becomes self-managing - it detects a condition and runs Python to respond, all on-box.

Enabling it (on a platform that supports it)

! Enable IOx (the app-hosting framework)
iox
!
! Enable and enter Guest Shell
guestshell enable
guestshell run bash

Inside, you have a Linux prompt. From there:

[guestshell]$ python3
>>> from cli import cli, clip, configure
>>> clip('show ip interface brief')      # run an IOS show, print the output
>>> configure(['interface Loopback50', 'ip address 10.50.50.1 255.255.255.255'])

That cli module is the bridge. Your Python, running in the Linux container on the router, drives the router's IOS configuration and reads its operational state. A script can loop over interfaces, make decisions, and reconfigure - entirely on the device.

The platform reality, stated honestly

Here is where PingLabz will not fake a screenshot. Guest Shell needs a full IOS XE platform with IOx - and on the virtual images available in our CML lab, it is not present. On the IOL-XE nodes we use for most routing labs, the command simply does not exist:

R1(config)#iox
              ^
% Invalid input detected at '^' marker.

IOL (the lightweight virtual IOS used for fast routing labs) has no IOx container framework, so there is no Guest Shell to enter. The heavier virtual platforms that do have the app-hosting stack (cat8000v, csr1000v) require the Data Management Infrastructure to initialise, which in a virtualised lab environment is itself unreliable. So we are not going to show you invented Guest Shell output on a platform that cannot produce it.

What is real, and what this whole cluster is built on, is the alternative: driving the router with Python from an external host. The Jinja2 + Netmiko pipeline renders configuration and pushes it to a real IOS XE device, verified end to end - all captured on the lab. That is off-box automation, and it does everything Guest Shell does except run on the device itself. For the vast majority of automation tasks, off-box is what you use anyway.

On-box vs off-box: when each makes sense

On-box (Guest Shell)
Runs: on the router itself
Best for: autonomous local reactions - a script that responds to a local event with no dependency on an external system
Needs: a platform with IOx, and container resources
Off-box (Netmiko, NETCONF, Ansible)
Runs: on an automation host, over SSH/NETCONF/RESTCONF
Best for: managing many devices consistently from one place, version-controlled config, CI/CD
Needs: just SSH/API access to the devices

The honest guidance: off-box automation is what you should reach for by default. It scales to your whole estate from one controlled place, it version-controls cleanly, and it works on every platform including IOL. Guest Shell is a specialist tool for the specific case where you need a script to run autonomously on a device with no external dependency - an edge router at a site with no reliable management connectivity that must self-heal locally, for instance. That is a real use case, but it is a narrow one.

What a Guest Shell script looks like (documented reference)

For completeness, a Guest Shell Python script that pulls interface stats and acts on them - the kind of thing you would run on a supported platform:

#!/usr/bin/env python3
from cli import cli, configure

# Read operational state via the CLI module
output = cli('show interfaces | include line protocol|input errors')

# Parse, decide, act - all on the router
for line in output.splitlines():
    if 'input errors' in line and int(line.split()[0]) > 1000:
        # High error count - shut the interface and log
        configure(['interface GigabitEthernet1', 'shutdown'])
        cli('send log "Guest Shell: high errors, interface shut"')

Launched from EEM on a trigger, this makes the router self-managing. We present it as a documented reference of the on-box model, clearly labelled, because it is real technology on a real platform - just not one our lab can boot.

Key takeaways

  • Guest Shell is a Linux container running on the router (via IOx), with Python and the cli module that lets on-box scripts drive IOS configuration and read operational state.
  • It enables autonomous on-box automation - a script that reacts to local events with no external dependency, especially powerful when launched from EEM.
  • It needs a full IOS XE platform with IOx. IOL (the lightweight virtual image) has no iox command, and the heavier virtual platforms' DMI is unreliable in a lab - so we describe it honestly rather than faking output.
  • The real, captured alternative is off-box automation: the Jinja2 + Netmiko pipeline that renders and pushes config to a live device, verified end to end.
  • Off-box is the default - it scales, version-controls, and works everywhere. Guest Shell is a specialist tool for genuine on-box autonomy.

Next: on-box Python: scripting IOS XE from the inside. The full cluster index lives on the network automation pillar.

Written by
More from Ping Labz
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Ping Labz.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.