Usually until they are 6-7 weeks old and have most of their adult plumage. They can be allowed outside for increasing lengths of time if the weather's nice, from about 1-2 weeks old, but must be kept in a safe container they can't escape from - I use an old child's playpen turned upside down on a patch of grass in the sun. Provide shade and water so they don't get too hot. You'll know if they aren't enjoying themselves - they huddle and cheep noisily if they are too cold, or pant with beaks open if too hot.
The best place to brood chicks is right in their coop. This assures that they have plenty of room, (by the time they are 2 - 3 weeks old, they should have about 2 s.f. of open space per chick) saves them the stress of moving from brooder to coop (chickens hate change) and if given enough space they will wean themselves off heat. Many of us have made the switch to brooding in the coop (even if we already have adult chickens) and use a heating pad cave instead of a heat lamp. It is much safer, more natural, and mimics the heat provided by a broody hen. Chicks should be completely weaned off heat by 4 - 5 weeks of age, depending on the season. (I'd give them longer if it was early spring, late fall, or winter) In the summer, based on ambient temps and number of chicks, you could plan on having your chicks completely off heat by 3 weeks, and even sooner if you use a wool hen or a huddle box.
I hatched my first eggs this year. I kept my chicks in a bedroom in a large plastic rabbit cage with sand as bedding I used what they call a electric hen to keep them warm and that set up was fine for my needs. As for allowing them outside i moved them out in the middle of July so bout 5-6 weeks but the weather was warm/hot that and we have a small insulated hardening off coop with attachable run so. My chicks were brahma's tho so unsure how others breeds would fair.
I'm with LG. A few years ago, many of us learned about the heating pad system of brooding and took it a step further and began brooding right outside in coop and run since the heating pad cave so closely mimics a broody hen.
So, in answer to your question, you do not ever have to brood in a container indoors. In fact, after I did it for the first time, I saw so many benefits I never realized were possible, I will never go back to putting baby chicks through the oppressive confinement of being brooded in a box under a hot light.
I wrote up an article about brooding outdoors linked below.