Heat and proteins are the cause of water boiling over when cooking pasta and other starchy foods, such as potatoes. Organic materials in the pasta in the form of proteins and starches are released into the water, increasing its surface tension and making the surface bubbles stretchy and pliable. This increases the amount of time it takes for a bubble to burst.
As the water boils, foam starts to form on the surface, where the bubbles stack under more bubbles that take too long to burst (soap makes suds in a similar way).This is known as a “foaming boil”, and eventually the stack of foaming bubbles rise and overflow.
How can you avoid this happening? Well if you add oil to the water, tiny oil droplets are formed with a different surface tension to the bubbles, causing them to pop when they encounter each other.