# New API launches extra environments

**URL:** <https://discuss.ray.io/t/new-api-launches-extra-environments/20176>\
**Category:** RLlib\
**Created:** [October 29, 2024, 11:22pm UTC](https://discuss.ray.io/t/new-api-launches-extra-environments/20176 "2024-10-29T23:22:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pitcherrr](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/pitcherrr/32/7211_2.png) [@Pitcherrr](https://discuss.ray.io/u/Pitcherrr)\
**Post date:** [October 29, 2024, 11:22pm UTC](https://discuss.ray.io/t/new-api-launches-extra-environments/20176/1 "2024-10-29T23:22:59Z")

</div>

**How severe does this issue affect your experience of using Ray?**

- High: It blocks me to complete my task.

I am transitioning to using the new API to train a PPO agent in my custom environment. My environment works fine for the old API where having **n** env\_runners launches **n** environments. Now the new api attempts to launch **n+1** , an extra environment for a process “PPO” and **n** for MultiAgentEnvRunner. Why is this extra environment being launched, is there a configuration I am missing? My config is as follows:

```auto
env_name = "ActionMaskEnv_V2"

register_env(env_name, lambda config: env_creator(config))

config = (
      PPOConfig()
      .api_stack(
          enable_rl_module_and_learner=True,
          enable_env_runner_and_connector_v2=True,
      )
      .environment(env=env_name)
      .learners(num_learners=1)
      .env_runners(num_env_runners=1, 
                   num_envs_per_env_runner=1,
                   rollout_fragment_length="auto", 
                   batch_mode="truncate_episodes",
                   sample_timeout_s=6000.0)
      .rl_module(
          # We need to explicitly specify here RLModule to use and
          # the catalog needed to build it.
          rl_module_spec=RLModuleSpec(
              module_class=ActionMaskingTorchRLModule,
              model_config={
                  "fcnet_hiddens": [256, 256, 256, 256],
                  "fcnet_activation": "tanh",
                  "vf_share_layers": True
              },
          ),
      )
      .training(
          train_batch_size_per_learner=4096,
          lr=1e-3,
          gamma=0.99,
          lambda_=0.95,
          clip_param=0.2,
          grad_clip=None,
          entropy_coeff=0.001,
          vf_loss_coeff=0.25,
          minibatch_size=128,
          num_epochs=10,
      )
      .multi_agent(policies = {"global"},
          policy_mapping_fn = lambda agent_id, episode, **kwargs: "global",
          count_steps_by="env_steps",
      )
      .debugging(log_level="DEBUG")
      .framework(framework="torch")
  )

```

---

<div class="post-metadata">

**Author:** ![Pitcherrr](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/pitcherrr/32/7211_2.png) [@Pitcherrr](https://discuss.ray.io/u/Pitcherrr)\
**Post date:** [October 30, 2024, 3:29am UTC](https://discuss.ray.io/t/new-api-launches-extra-environments/20176/2 "2024-10-30T03:29:14Z")

</div>

From [Environments — Ray 2.38.0](https://docs.ray.io/en/latest/rllib/rllib-env.html)

 ![image](https://us1.discourse-cdn.com/flex020/uploads/ray/original/2X/a/a3db27e69c32d466c6347a26c13b0887214ddb96.png)

I will be moving env init to the reset function.
