Guide: Google Colab

Welcome! If the words “notebook,” “code cell,” or “runtime” mean nothing to you yet, you are in exactly the right place. This guide walks you from “what is this?” all the way to “I finished the activity and submitted it,” with nothing to install and no coding background assumed. Take it one numbered step at a time. You cannot break anything.

1. What this is and why CIS 350 uses it

Google Colab (short for “Colaboratory”) is a free tool that lets you write and run Python code inside your web browser. There is nothing to download and nothing to set up on your computer. If you can open a web page and sign in to a Google account, you can use Colab.

A Colab document is called a notebook. Think of a notebook like a lab worksheet that can actually do the math for you. It is made of stacked boxes called cells. Some cells hold plain writing (instructions, questions); other cells hold code you can run with one click, and the result appears right underneath. You read top to bottom, running the code boxes in order, just like following a recipe card by card.

Here is the real-world analogy: a normal recipe card only tells you what to do. A Colab notebook is a recipe card with a “cook this step” button on every instruction. You press the button on step 1, watch it happen, then press step 2, and so on. By the end, the dish (your analysis, your chart, your captured flag) is done.

CIS 350 uses Colab for everything hands-on: every lab (Weeks 1-8 and 10-13), the Week 1 Python and Colab tutorial, and every Capture-the-Flag (CTF) challenge starter. We chose it because it is free, it works the same on any laptop, and the powerful data-science tools we need are already built in. You focus on learning, not on installing software.

2. Before you start / first-time setup

You need one thing: a Google account (a Gmail address, or your GW Google account). If you already use Gmail, you are ready. Follow these steps once.

  1. Open a web browser (Chrome works best) and go to https://colab.research.google.com.
  2. You will see a blue-and-white welcome window titled “Welcome to Colaboratory.” Look at the top-right corner of the screen for a Sign in button and click it.
  3. Type your Google email address, click Next, type your password, and click Next again. (If your school account asks for two-step verification, approve it on your phone.)
  4. You are now signed in. In the top-right corner you should see your account initial or profile picture in a circle. That circle is how you confirm you are logged in.
  5. To make your very first notebook, click the File menu in the top-left, then click New notebook. A fresh notebook opens in a new tab, with one empty code cell in the middle.
Note: You do NOT need to install Python, and you do NOT need to buy anything. Colab is free for the work we do in this course. If a page ever tries to sell you "Colab Pro," you can ignore it - the free version is all you need.

That is the entire setup. Colab automatically saves your notebooks to your Google Drive, so there is no “save file to my computer” step to worry about yet.

3. A guided tour of the interface

Annotated diagram of the Google Colab screen with a numbered key pointing to the menu bar, the plus-Code and plus-Text buttons, the Run button, the output area, and the Connect button

Figure 1. The main Colab screen. This is an illustration to help you find things - the real page may look slightly different, but the labeled parts are always in these areas.

Side-by-side comparison of a code cell (gray, runs Python) and a text cell (white, holds notes written in Markdown)

Figure 2. A notebook is a stack of cells. Code cells run Python; text cells hold notes and your written answers.

When a notebook is open, the screen has three main areas. Here is a simple sketch of the layout:

+-----------------------------------------------------------+
|  File  Edit  View  Insert  Runtime  Tools  Help    (menus)|
|  [ + Code ]  [ + Text ]                    (add-cell bar)  |
+-----------------------------------------------------------+
|  (O)  | import pandas as pd                                |  <- a CODE cell
|  Run  | df = pd.read_csv("...")                            |
+-----------------------------------------------------------+
|         This is a text cell explaining the step.          |  <- a TEXT cell
+-----------------------------------------------------------+

Here is what to look for:

The single most important habit: run the code cells in order, from top to bottom. Later cells depend on earlier ones having run first.

4. How you will use it in this course

Almost everything hands-on happens in Colab. You will mostly open a starter notebook we provide, fill in the blanks marked TODO, run the cells, answer a few questions in text cells, and submit the finished notebook. Here is the map:

Week(s) What you use Colab for What you do How you submit
1 Python & Colab tutorial (Activity 1) Work through a gentle intro: run cells, learn just-enough Python Follow along; no upload needed unless your instructor asks
1-8, 10-13 The 12 graded Labs (50 pts each) Open the lab starter.ipynb, fill the TODO blanks, answer 5 guided questions Download the completed .ipynb and upload it in Canvas
8 CTF: Evade the Filter (15 pts) Modify a phishing email so a classifier scores it benign Run the check cell, submit the CIS350{...} flag on CTFd
10 CTF: One Pixel Too Far (20 pts) Add a tiny perturbation so a model misreads a digit Submit the flag on CTFd
11 CTF: Jailbreak the Helpdesk Bot (20 pts) Craft a prompt injection that makes a bot leak its secret Submit the flag on CTFd
13 CTF: Were You in the Data (20 pts) Run a membership-inference attack Submit the flag on CTFd
15 CTF: The Aging Malware Detector (20 pts) Fine-tune a stale detector with limited labels Submit the flag on CTFd

For the full picture of weekly work, see the Activities page and the Labs page. Brand-new to all of this? Start with the Python & Colab Bootcamp slides linked at the top of the Labs page before Lab 1.

Two submission destinations - do not mix them up: Labs are submitted as a .ipynb file in Canvas. CTF challenges are submitted as a short CIS350{...} flag on the CTFd server. The notebook is how you *get* the flag; CTFd is where you *turn it in*.

5. Step-by-step: completing an activity end to end

Six-step workflow diagram: get the starter .ipynb, then File to Upload notebook, then choose the file, then Runtime to Run all, then do the TODO cells and read each output, then download or share and submit in Canvas

Figure 3. The same six steps work for every lab and every CTF starter notebook.

The one step new students hunt for is where to open the starter file. It lives in the File menu at the top-left: click File, then Upload notebook (highlighted below).

Zoomed view of the Colab File menu dropdown open, listing New notebook, Open notebook, Upload notebook (highlighted), Save, and Download .ipynb, with a callout explaining that Upload notebook opens a lab or CTF starter

Figure 4. Opening a starter notebook: File -> Upload notebook. Illustration - your screen may differ slightly.

Let’s walk through a typical lab (for example, Lab 2 - Exploring Security Data, where you analyze a phishing-email dataset). Every lab and CTF starter follows this same rhythm.

  1. Get the starter file. Download the lab’s starter.ipynb from Canvas (or the link on the course site) to your computer. You will see a file ending in .ipynb - that is a notebook file. You do not need to open it on your computer.
  2. Open Colab and upload it. Go to https://colab.research.google.com, sign in, then click File -> Upload notebook. In the window that appears, click Browse, choose the starter.ipynb you just downloaded, and it opens in Colab.
  3. Rename it so it is clearly yours. Click the file name at the top-left (e.g. starter.ipynb) and change it to something like Lab02_YourName.ipynb. Press Enter.
  4. Read the top text cell. The first cell explains the task. Read it before touching anything.
  5. Run the setup cell. The first code cell usually loads the tools and the data. Click the round Run button on its left edge (or click inside the cell and press Ctrl+Enter). Wait for the spinning circle to stop and a [1] to appear. A common first cell looks like this:

    import pandas as pd
    df = pd.read_csv("https://example.com/emails.csv")   # the real URL is in your starter
    df.head()
    

    pd.read_csv(...) loads a spreadsheet-style file from a web address into a table called a DataFrame (we nickname it df). df.head() then prints the first five rows so you can see what you are working with.

  6. Work down the notebook, one cell at a time, in order. Fill in any blank marked # TODO by typing the small piece of code the instructions ask for, then run that cell. Helpful commands you will see:
    • df.shape - tells you how many rows and columns the table has.
    • df.describe() - prints quick statistics (averages, min, max) for the number columns.
    • df["label"].value_counts() - counts how many emails are phishing vs. legitimate.
  7. Make the chart. Many labs ask for a simple bar chart. The starter gives you most of it; you run the cell and a plot appears right below it, for example:

    import matplotlib.pyplot as plt
    df["label"].value_counts().plot(kind="bar")
    plt.show()
    
  8. Answer the guided questions. Scroll to the text cells that ask questions. Double-click one, type your answer under the question, then click anywhere outside the cell to lock it in.
  9. Do a clean final run. Click the Runtime menu -> Restart and run all. This clears everything and runs the whole notebook fresh from the top, proving your work runs start-to-finish without errors. Watch it complete with no red error boxes.
  10. Save (it is automatic). Colab saves to your Google Drive every few seconds - you will see “All changes saved” near the top. To force a save at any time, press Ctrl+S or use File -> Save. Your notebooks live in a Drive folder called “Colab Notebooks,” so there is no “save to my computer” step to worry about.
  11. Download the finished notebook. Click File -> Download -> Download .ipynb. Your browser saves one file ending in .ipynb to your Downloads folder - it contains all your code, results, charts, and answers. This single file is what you submit for a lab.
  12. Submit it in Canvas. Open your course in Canvas ([your Canvas course URL - posted on Canvas]) and open the correct lab assignment. Click Start Assignment, choose File Upload, click Choose File (or Browse), and select the .ipynb you just downloaded. Confirm the file name is your lab (e.g. Lab02_YourName.ipynb), then click Submit Assignment. You should see a confirmation and the submission time.

For a CTF challenge the flow is the same until step 8: instead of answering questions in text cells, you run the final check(...) cell. When it prints SUCCESS! Flag: CIS350{...}, copy the whole flag, go to the course CTFd server ([your course CTFd URL - posted on Canvas]), open that week’s challenge, paste the flag into the answer box, and click Submit. A green “Correct” means you earned the points. For CTFs you submit the flag on CTFd, not the notebook - though you may also record your code and reflection in that week’s worksheet if the activity asks.

Sharing a link (only if asked, e.g. group work): click the Share button in the top-right corner, under "General access" choose Anyone with the link and set the role to Viewer, then click Copy link. For graded labs, upload the .ipynb to Canvas rather than sharing a link, unless your instructor says otherwise.

6. Troubleshooting

Errors are normal and expected - even professionals hit them constantly. When something goes wrong, Colab prints a red box under the cell. Read the last line of that red box; it names the problem. Here are the five you are most likely to meet and the exact fix for each.

A single Colab code cell running print of df.head with a red-tinted error output box reading NameError: name df is not defined, and a callout showing the fix

Figure 5. A typical red error box and its fix - run the earlier cell that defines the variable. Illustration - your screen may differ slightly.

What you see (in the red box) What it means The exact fix
NameError: name 'df' is not defined You tried to use something before creating it - usually you skipped an earlier cell. Scroll up and run the earlier cell (the one that defines df) first, then re-run this one. Easiest: Runtime -> Restart and run all.
ModuleNotFoundError: No module named '...' The code used a tool that was never brought in. Add the missing import at the top, e.g. import pandas as pd or import matplotlib.pyplot as plt, and run that cell. (Note: pandas, numpy, scikit-learn, and matplotlib are already installed - you never need pip install for these.)
FileNotFoundError or an HTTP error on read_csv The web address (URL) for the data is mistyped or the file moved. Check the URL inside pd.read_csv("...") matches the one in the instructions exactly - watch for missing quotes or a truncated link.
IndentationError A line of code has the wrong amount of space at its start. Lines inside a block must be indented consistently. Line up your line with the others around it (use spaces, not random tabs).
Cells behaving oddly, wrong numbers, or “it worked before and now doesn’t” You ran cells out of order and the notebook is confused. Click Runtime -> Restart session (or Restart and run all) to wipe everything clean and start fresh from the top.
The one fix that solves most problems: Runtime -> Restart and run all. It resets Colab's memory and runs every cell in the correct order. When in doubt, try this first.

A few more quick answers:

7. Ethics and responsible use

Read this before any security activity. Everything you attack in this course - every spam filter, model, and chatbot in a lab or CTF - is an intentionally weak "toy" built only for this class and running only in the Colab sandbox we give you. These are not real systems, companies, or people.

8. Getting help + quick-reference checklist

Where to get help, in order:

  1. Re-read the red error box’s last line and check the Troubleshooting table above.
  2. Try Runtime -> Restart and run all.
  3. Post your question on the course discussion board or in office hours - paste the exact red error text so we can help fast.
  4. Review the Python & Colab Bootcamp slides linked on the Labs page.

Before any hands-on security activity, re-read the ethics and responsible-use rules in Section 7 above.

Quick-reference checklist - glance at this during any activity:

You have got this. Work through it one cell at a time, and remember: restarting the runtime fixes most surprises.