Cook the spaghetti in plenty of salted water and broth to taste until firm to the bite.
Preheat the oven to approx. 180 ° top / bottom heat or circulating air (depending on the stove).
Cut the ham into finger-width strips, dice the onions and dice the garlic.
Let the pan get hot, add butter or olive oil to the hot pan, then fry the ham evenly. Add the onions, stir everything well. Add the garlic and fry briefly. Deglaze with the 1.5 cups (approx. 350 ml) vegetable stock. Let simmer for 2-3 minutes. Then add the sour cream and stir in. Season with salt and strong pepper, add chilli to taste. If the sauce becomes too runny, a piece of cold butter can help or, in an emergency, a sauce thickener can be used. The sauce should have a nice creamy consistency.
Drain the spaghetti and add a good amount of butter to the pasta. While the butter in the pasta is melting, rub the baking dish with a little olive oil. Put the pasta in the pan, pour the sauce over it and stir everything in well. Spread the grated cheese on the pasta and bake in the oven. It tastes best when the cheese has run straight and is still pulling nice threads.