GitHub Copilot for Network Automation: A Practical Tutorial

This post is a hands-on tutorial for IT professionals on using GitHub Copilot to accelerate network automation scripting. It covers setup in VS Code, generating Netmiko scripts from comments, using Copilot Chat for refactoring, and best practices for reviewing AI-generated code safely.

GitHub Copilot for Network Automation: A Practical Tutorial
Quick answer

GitHub Copilot is an AI coding assistant that suggests code inside your editor as you type. For network automation, describe the task in a comment, for example connecting with Netmiko and running show ip interface brief, accept the suggested skeleton with Tab, then review it, move credentials into environment variables or a vault, and test it in a lab before it goes near production.

If you've spent any time writing Python scripts to manage network devices, you know the drill: open your editor, stare at a blank file, type out the same boilerplate imports for the hundredth time, and then slowly build out your logic. GitHub Copilot changes that workflow significantly. It's an AI coding assistant built directly into your editor that suggests code as you type, turning what used to take an hour into something you can knock out in minutes.

This guide walks you through setting up GitHub Copilot and using it practically for network automation tasks. We'll keep it concrete with real examples so you can see exactly what the tool does.

What Is GitHub Copilot?

GitHub Copilot is an AI coding tool developed by GitHub and OpenAI. It integrates with editors like VS Code, JetBrains IDEs, and Neovim, and it generates code suggestions based on your comments, function names, and surrounding context. It's powered by a large language model trained on billions of lines of public code.

For network engineers, the value is immediate: you describe what you want in a comment, and Copilot writes the script skeleton for you. You still review and refine the output, but the heavy lifting of scaffolding repetitive tasks is handled automatically.

Pricing starts with a free tier for individual users (with usage limits), and paid plans are available at github.com/features/copilot.

Setting Up Copilot in VS Code

Getting started takes about five minutes:

  1. Install Visual Studio Code from code.visualstudio.com
  2. Open the Extensions panel (Ctrl+Shift+X) and search for GitHub Copilot
  3. Install the extension and sign in with your GitHub account
  4. Accept the Copilot subscription prompt if you're on a free or paid plan

Once installed, Copilot runs silently in the background. When you start typing in a Python file, suggestions appear as faded "ghost text." Press Tab to accept a suggestion, or Escape to dismiss it.

Writing a Network Automation Script with Copilot

Let's say you want to write a Python script that connects to a Cisco router via SSH and pulls the output of show ip interface brief. Normally you'd manually write out your Netmiko imports, your connection dictionary, and your send command call. With Copilot, you start with a comment and let it lead.

Open a new file called check_interfaces.py and type the following comment:

# Connect to a Cisco IOS router using Netmiko and run 'show ip interface brief'

Copilot will typically suggest something very close to this:

from netmiko import ConnectHandler

device = {
    "device_type": "cisco_ios",
    "host": "192.168.1.1",
    "username": "admin",
    "password": "cisco123",
}

connection = ConnectHandler(**device)
output = connection.send_command("show ip interface brief")
print(output)
connection.disconnect()

That's a working Netmiko script generated from a single comment. You still need to review it, replace the credentials with environment variables or a vault solution, and test it in your lab. But the scaffolding is done instantly.

Using Copilot Chat for More Complex Tasks

The Copilot Chat panel (available in VS Code via the sidebar) lets you have a back-and-forth conversation about your code. This is particularly useful for IT scripts where requirements are more nuanced.

Some useful prompts to try in Copilot Chat for network automation:

  • "Refactor this script to loop over a list of devices": converts your single-device script into a multi-device one automatically
  • "Add error handling for SSH timeouts": wraps your connection logic in proper try/except blocks
  • "Write a function to parse this output into a dictionary": great for turning raw CLI output into structured data
  • "Add logging to this script using the Python logging module": scaffolds a full logging configuration for you

Best Practices When Using Copilot for IT Scripts

Copilot is a powerful accelerator, but it requires a thoughtful operator. Keep these habits in mind:

  • Always review suggestions before accepting: Copilot can suggest deprecated methods or insecure patterns like hardcoded credentials
  • Use descriptive comments: the more specific your comment, the better the suggestion quality
  • Test in a lab first: never run a Copilot-generated script directly on production devices without validation
  • Use environment variables for credentials: replace any hardcoded values with calls to os.environ.get() or a secrets manager

GitHub Copilot for network automation: common questions

How do I get Copilot to write a network script?

Write a specific comment describing what you want, such as connecting to a router with Netmiko and running a show command, and Copilot suggests the code. The more specific the comment, the better the suggestion.

Is code generated by Copilot safe to run on production devices?

Not without review and testing. Suggestions can use deprecated methods or insecure patterns such as hard-coded passwords, so check every line and test in a lab first.

Where should credentials go in an automation script?

Not in the script. Read them from environment variables, for example os.environ.get(), or from a secrets manager.

What can Copilot Chat do that inline suggestions can't?

It lets you ask for changes to existing code in conversation, such as looping over a device list, adding SSH timeout handling, parsing output into a dictionary or adding logging.

How do I accept or reject a Copilot suggestion in VS Code?

Suggestions appear as faded ghost text: press Tab to accept, or Escape to dismiss.

What's Next

Now that you have Copilot generating your script skeletons, the next logical step is learning how to structure those scripts properly for real network environments. In the next post, we'll cover how to use Netmiko to manage multiple devices at scale, including how to loop over device inventories, handle exceptions gracefully, and log output to file. That knowledge pairs perfectly with what Copilot can generate, giving you both speed and reliability in your automation workflow.

๐Ÿ”ง
If you're writing network automation scripts, GitHub Copilot is worth trying โ€” just drop a comment describing what you want and it scaffolds the boilerplate instantly. Tabnine and Codeium are solid alternatives if you prefer something that can run locally or without a GitHub subscription. GitHub Copilot, Tabnine and Codeium.