Heat oven to 350 degrees F and arrange rack in middle. Butter 4 (6-ounce) ramekins and set aside.
Melt 1 tablespoon butter in a large frying pan over medium heat. When it foams, add onion, season well with salt and freshly ground black pepper, and cook until softened, about 1 minute. Add spinach and cook until spinach is well wilted, about 2 minutes.
Place ham on bottom of ramekins and top with spinach. Crack eggs into ramekins, place 1 tablespoon cream over each egg, and divide half of cheese evenly among ramekins.
Put ramekins on a baking sheet and bake, rotating pan halfway through baking, until whites are just set but yolks are still runny, about 15 to 18 minutes.
Meanwhile, spread remaining 2 tablespoons butter on 4 slices sourdough bread. Top with grated cheese and toast until golden brown. Serve eggs with toast.