Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

What not to paste into an AI assistant

After this lesson: I can name what not to paste into an assistant and what generated code gets wrong.

60 min lesson2 commandsAI coding agent lab: use opencode to explain and fix code, and check its work

What you type leaves your machine

Using an AI assistant safely means knowing two things. Your request and your code are sent to a model, and the code it sends back can contain security faults. It matters because a password pasted into a prompt cannot be taken back.

A developer pastes a whole config file to ask about one setting. The file also held a database password.

By the end of this lesson

Note

I can name what not to paste into an assistant and what generated code gets wrong.

Key words

WordWhat it means
Secreta password, key or token that proves who you are
Personal datafacts about a real person
Placeholdera made-up value that stands in for a real one
Injectioninput that is treated as code
Rotateto replace a secret with a new one

The cells students fill in are left blank in this preview.

Four things never to paste into a prompt

Do not paste secrets: passwords, keys and tokens. Do not paste personal data, such as names, emails or grades of real people. Do not paste code you have no right to share.

And do not paste anything your employer or college has said must stay private. Ask first when you are not sure.

Worked example: what to do instead

Do not pasteWhyPaste this instead
A real API keyIt could be used by anyone who sees itThe word API_KEY as a placeholder
A list of student names and marksIt is personal data about real peopleThree invented rows with the same shape
A whole config fileIt may hold more than the one settingOnly the lines you ask about, cleaned
A customer's emailIt identifies a person[email protected]

The cells students fill in are left blank in this preview.

Search made-up text for a key line

Command
docker exec agent sh -c "printf 'user=ada\nAPI_KEY=abc12345\n' | grep -n KEY"

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

A search can catch a secret

The command made up two lines of text and searched them for the word KEY. It printed 2:API_KEY=abc12345: the line number, a colon and the line.

The value here is invented. A real check, the one you write in the assignment, looks for several signs at once. It is a safety net, not a guarantee.

A common mistake

Warning

Many people think they can undo a pasted secret by deleting it in the next message. Once sent, it has left your machine. Treat it as exposed: rotate it, which means replacing it with a new one, and tell whoever owns it.

See what the lab's assistant must ask first

Command
docker exec agent grep -o '"permission".*' /home/node/.config/opencode/opencode.json

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

The assistant asks before it edits or runs

The line above is the lab's own setting. It says the assistant asks before it edits a file, asks before it runs a command and is refused any web fetch.

Those questions are your chance to review. Read what it wants to do before you say yes. A yes you did not read is the same as a paste you did not check.

Generated code repeats common security faults

A model learned from a great deal of public code, and much of it is insecure. So its code can build a database query by joining text. It can put a password into the source. It can trust input without checking it.

The first one is called injection. Read the two functions below. Neither is run in this lesson.

Two ways to ask a database

Code: python
def find_member(db, name):
    # Risky: the name is glued into the query text.
    return db.execute("SELECT * FROM members WHERE name = '" + name + "'")

def find_member_safely(db, name):
    # Safer: the name travels apart from the query.
    return db.execute("SELECT * FROM members WHERE name = ?", (name,))

Worked example: faults in generated code

FaultWhat it looks likeThe safer way
InjectionInput joined into a query with +Pass the input as a separate parameter
Hard-coded secretpassword = "..." in the sourceRead it from the environment
Unchecked inputUsing a value before testing itCheck type, length and range first
Invented packageAn import of a name that does not existCheck the package is real and trusted

The cells students fill in are left blank in this preview.

About this lab and its source: AI coding agent lab: use opencode to explain and fix code, and check its work

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.