A cookie is a very small text file that a website asks your browser to store on your device. It usually holds a name, a short value (often a random code) and an expiry date. That is all. A cookie cannot run code, carry a virus, or look at your files.
Cookies exist because the web has no memory by default. Every page request is a stranger knocking on the door. Cookies give a website a way to say “oh, it’s you again” and remember something small: that you are signed in, that you picked a setting, or that a visit is one continuous visit rather than ten separate ones.
They are named after the “magic cookie”, an old computing term for a token passed between programs. The name is the only sweet thing about them.