I am constantly surprised that people don't do this.
You are paid to do a job - usually that job is to do what your boss tells you!
So, do your job well, by doing what your boss asks you to do. Immediately!
When your boss (team leader, senior developer, CEO) asks you to do something, no matter how vaguely articulated or even just requested as 'if you get a chance', make sure you drop everything and do it immediately.
What to do when your boss's boss asks you to directly do something (ie they bypass your boss)
1. Work out how long it will take
2. Tell your boss (let's call him Kevin), that your boss's boss (let's call her Therese) has asked you to do X, and you think you will have it finished in Y hours/days. Check it is OK to continue, but with an attitude that you are already working on it.
3. Finish the task as soon as possible (stay back to get it complete if required)
4. Give it to your boss (Kevin) and ask them to forward it onto their boss (Therese)
5. Return to what you were doing and don't make any further mention of it
Here's what happens:
1. Bob feels included, and in some way responsible for providing the result to his boss (since he did allow you to continue with the work)
2. Therese is pleased that she got her result very quickly
3. Therese knows it was you who did it and also knows that you must have supplied it to Bob
4. She knows that Bob knows she didn't go through him (when she should have) but since she got the result back quickly (via him) that next time she should request it through him (and not bypass him).
You have kept your boss on side, and pleased your boss's boss. Everyone wins.