If water fills up in your basement window wells and runs inside, you will need drains in the wells. Either the soil won't drain or the groundwater level is so high that there is no place for water to flow.
In either case, dig a drainage ditch underneath the window well and install drainpipes that are sloped to carry the water away from the house. These can direct the water to the foundation drains by the house that will carry the water away to the street and protect the basement.
Another option if there’s insufficient room for drainpipes is to install a sump pump with additional piping to pull out the water and push it away from the house. This will also prevent water from getting through the window well and into the basement. You can also dig a series of trenches that diverts the water far enough away from the house that it can drain into the soil. It might cause a bunch of muddy patches in the yard, but it’s better than a flooded backyard. Contractors will also often dig deeper into the well and add gravel to help with the drainage. Retaining walls might be worth consideration, depending on the landscaping situation of your home and yard.
To prevent drainage problems, clean out the well at least six inches below the window level and backfill with small gravel to within 3 inches of the window ledge. Caulk any cracks or openings around the window. Make sure downspouts carry water several feet away from the house.