Preheat the oven to 400°F.
Combine the cherry tomatoes and red onion on a medium-size sheet pan. Drizzle the tomatoes and onion with balsamic vinegar and olive oil, and season them with with a pinch of salt and pepper. Toss everything on the sheet pan to combine.
Wrap the garlic cloves in aluminum foil and place on the sheet pan.
Roast the tomatoes, onion, and garlic cloves in the oven for about 20 minutes, until the balsamic has reduced and caramelized the onions and the tomatoes are soft and blistered.
Meanwhile, bring a pot of salted water to a boil. Cook the spaghetti al dente, according to package instructions. Drain in a colander, making sure to reserve a bit of pasta water.
When the red onions and cherry tomatoes are ready, pull them out of the oven. Carefully unwrap the garlic gloves and, using a fork, mash them on the sheet pan until they are soft and broken up.
Sprinkle the basil, plus another pinch of salt and pepper, over the sheet pan and toss to combine with the mashed garlic, tomatoes, and onion.
Add the pasta to the sheet pan, plus a splash of pasta water and toss to combine. Serve warm, sprinkled with Parmigiano-Reggiano and extra basil sprigs, if you like.
