Some of these pictures and descriptions may give away plot details that you might not want to know before watching the film.
This is one of the few big budget Michael Bay action movies that wasn't a huge hit at the box office. It's sort of an update of Logan's Run, the 1976 Sci-Fi classic. Ewan McGregor and Scarlett Johannson have just escaped from a giant corporate cloning complex hidden deep underground in an old military bunker in the Arizona desert some time in the near future. They were raised in what they were taught to believe is an underground utopia populated by survivors of a mass contamination event that killed almost all life on earth, which they find out is a lie once they escape. The first living creature they see after they get outside is a rattlesnake. They don't know what it is, but the fact that it's alive is proof to them there is still life outside the complex. Like all movie rattlesnakes it rattles constantly and strikes, because all movie rattlesnakes have to strike at someone or the producers aren't getting their money's worth from the snake wranglers. Also, Ewen McGregor reminds us that rattlesnakes are just plain mean and not simply defending themselves, in order to keep that myth alive for all the other directors who want to stick a snake in their movie. But at least they leave the snake alone and keep running instead of killing it we see in most movies. They could have just used a jackrabbit to prove the same point, so maybe the two are supposed to learn that there are dangerous animals outside the complex besides the mercenaries in black helicopters who are hunting them. Or maybe they just used a rattlesnake to excite us because that's what big macho action movies are about, but I'm still including this as one of the rare appearances of a rattlesnake or any other kind of snake in a movie that is shown fairly realistically because it isn't used here only to provide a convenient dramatic plot-change device like a snakebite or a heroic snake killing.
The snake used in the scene is a location-appropriate Western Diamond-backed Rattlesnake. I don't know how they filmed the encounter. Visual effects are so good now that they can make me belive anything, but it looks like the actors were actually in the frame with the snake, so they may have just used the old school technique of putting a pane of glass between them and the snake. It even looks like the snake hits the glass when it strikes, to back up my theory.