This paper presents BiasGym, a novel framework for understanding and mitigating biases and stereotypes inherent in large-scale language models (LLMs). BiasGym consists of two components: BiasInject, which injects specific biases through token-based fine-tuning without altering the model's weights, and BiasScope, which utilizes the injected signals to identify and adjust the causes of biased behavior. BiasGym enables mechanism analysis through consistent bias induction, supports targeted bias mitigation without compromising subtask performance, and generalizes to biases unseen during token-based fine-tuning. It demonstrates effectiveness in reducing real-world stereotypes (e.g., Italians are "reckless drivers") and fictional associations (e.g., people from fictional countries have "blue skin"), demonstrating its utility in both safety interventions and interpretability studies.