Elements Of A Sandbox Game
A sandbox style game is any game were you can choose to not further the main storyline at will. Most popular of this topic would be the Grand Theft Auto series, but games such as SaGa, Legend of Mana, Shenmue, Monster Hunter, Fallout 3, The Elder Scrolls, Assassin's Creed, Xenoblade, Dark Souls, and even technically Burnout Paradise, are examples of this concept as well.
Just as important as doing what ever you want is doing what ever you want in a open world. Sandbox games tend to have level designs such as cities or open geography for one to roam with very little restrictions such as invisible walls. A game like Project Gotham Racing may have city streets to drive in, but games such as Need for Speed: Most Wanted allow you to drive around said city as one sees fit.
Games such as Metroid or Shadow Complex are not Sandbox games even though they allow you to explore, because the only way to progress through the game (outside of game-breaking exploits) is by taking a specific path, collecting items and fighting bosses in an order predetermined by the developers.
User Generated Content
In a true "sandbox", the player has tools to modify the world themselves and create how they play. This can come in the form of user generated content.