I have a device in a box which has parts of metal. So can I prevent corrosion by creating a vacuum around the metallic object?
The word corrosion has a range of meanings, but it is generally taken to indicate the chemical reaction of a material with its environment. For example iron corrodes by reacting with oxygen in the air (or water if it's underwater).
If you put the metal in a vacuum then it doesn't have anything around it to react with, so in this case yes putting the metal in a vacuum will stop it corroding.