01 - Preheat the oven to 400°F. Line a baking sheet with parchment paper for easy cleanup.
02 - Cut the spaghetti squash in half lengthwise. Scoop out and discard the seeds. Brush the cut sides with 1 tablespoon olive oil and season generously with salt and pepper.
03 - Place squash halves cut-side down on the prepared baking sheet. Roast for 35 to 40 minutes until tender, checking that strands easily pull away with a fork.
04 - While the squash roasts, heat the remaining tablespoon of olive oil in a large skillet over medium heat. Add the sausage and cook, breaking it up with a wooden spoon, until browned and cooked through, about 6 to 7 minutes.
05 - Add the onions and bell peppers to the skillet. Sauté for 5 minutes until softened. Stir in the garlic, oregano, basil, and red pepper flakes if using. Cook for 1 minute more until fragrant.
06 - Pour in the marinara sauce. Let the mixture simmer for 5 minutes to allow the flavors to meld, then remove from heat.
07 - Once the squash is cool enough to handle, use a fork to scrape the flesh into spaghetti-like strands. Discard the skins.
08 - Reduce the oven temperature to 375°F for the final baking step.
09 - In a large mixing bowl, combine the squash strands, sausage mixture, half of the mozzarella, and half of the Parmesan. Mix thoroughly and adjust seasoning to taste.
10 - Transfer the mixture to a greased 9x13-inch baking dish. Top evenly with the remaining mozzarella and Parmesan.
11 - Bake uncovered for 15 to 20 minutes until the cheese is melted and bubbly with golden-brown spots.
12 - Let the casserole rest for 5 minutes before serving. Garnish with fresh basil if desired.