Snakes don't exactly "defend their territory", though they might personally feel cornered & threatened*. But no, that wasn't what yours was doing.

He was hoping your warm & wiggling hand was his incoming dinner. Fortunately he realized pretty fast that he didn't want the "special of the day".

Hey, don't forget these little guys have heat sensing pits, & they USE them.

When a snake looks a "little too interested", believe them.

And if you've been wearing hand sanitizer, but not this time, that might have been just enough for him to think "Hey, maybe this IS it?" I trust you'll survive?
(*Might be some exceptions as far as "territory defense"- like maybe king cobras? But I don't think most snakes have a sense of "territory".)
BAD Wiggles!

NO soup for you!