Respect should always be a prime consideration - respect for other people's space, equipment and the music played.
It wouldn't hurt to 'survey' the scene first, as in, get to know who the players are and the songs they play, and gauge yourself accordingly if you deem yourself 'fit' for such an environment.
Now, even if you do feel you're more than qualified to jam, make sure you politely ask any of the band members if it's ok to sit in and play a tune or two.
When you get that far enough and actually do get asked to sit in, be very, very careful with the other person's equipment (assuming you didn't bring your own guitar or bass). Which means being careful with the belt buckle or anything that could cause scratches or dents on the instrument.
Being a guest jammer usually means being the one to call the tune. For practicality, it's best to stick to familiar tunes that most players would know. Don't say, "Giant Steps in F# in 9/8!!!"
Be mindful of your volume level, especially when soloing. Leave your Spinal Tap impressions at home. Likewise for your Metal Zone pedal ..
Always take your cue from the band leader as to when to solo. The worst thing you can do is abruptly cut someone off in mid-solo.
Most important of all: keep your solos short
If you've made it through your first tune, check if the audience (and the band) is still awake. If they want to hear more from you, they'll prod you on. Otherwise, that's your cue to step down.
When you do go offstage, never fail to thank the guy you borrowed your instrument from, and the rest of the band as well - and be quick in doing so.