Can a child get worms from a pet that is inside and outdoors?

Yes. Typically caught with fecal oral contact. Hand washing is one of the best ways to prevent it, without removing the pet from the child.