Canon explains that 'accidental' magic occurs in relation to strong emotion(s) -- this means a witch or wizard can make magic happen without meaning to and without having a wand to channel the magic through. Here's some examples from canon that help to explain this. In Philosopher's Stone:
- Aunt Petunia cuts Harry's hair practically to the scalp, because she's tired of Harry coming back from the barber's looking like he hadn't gotten a haircut. The next morning, Harry's hair had miraculously grown back to its normal length.
- Aunt Petunia tried to force Harry into an old ugly jumper of Dudley's, but the more she tried to pull it over Harry's head, the smaller the jumper got, until it was the size of a handpuppet.
- Harry inexplicably found himself on top of the roof of his school's kitchen when he was running from Dudley and Dudley's gang, and Harry had no idea how he got up onto the roof.
- The boa constrictor incident, where Harry removed the glass to the snake's habitat.
And to answer your question, which is specifically about the boa constrictor incident, I think Hagrid sums it up nicely:
‘Not a wizard, eh? Never made things happen when you was scared, or angry?’
Harry looked into the fire. Now he came to think about it ... every odd thing that had ever made his aunt and uncle furious with him had happened when he, Harry, had been upset or angry ... chased by Dudley’s gang, he had somehow found himself out of their reach ... dreading going to school with that ridiculous haircut, he’d managed to make it grow back ... and the very last time Dudley had hit him, hadn’t he got his revenge, without even realising
he was doing it? Hadn’t he set a boa constrictor on him?
Philsopher's Stone - Page - Bloomsbury - Chapter 47, Keeper of the Keys