Author an Environment
Author environments with EnvFactory for local runs, serving, and managed evaluations.
Start with EnvFactory when authoring an environment. The same class constructs environments for local evaluations, serving, task sweeps, and managed containers. Put construction in make(), optional one-time setup in prepare(), and adapter roles in tags. If you only need to expose an existing environment object, serve it directly with EnvServer.
A minimal factory
Implement make() and return a Gymnasium-style environment. Keep heavyweight imports inside the method so RLMesh can inspect the factory without loading the simulator.
import rlmesh
class CartPole(rlmesh.EnvFactory):
def make(self):
import gymnasium as gym
return gym.make("CartPole-v1")
if __name__ == "__main__":
CartPole().serve("127.0.0.1:5555")
Use the same factory in a local evaluation (model.run(CartPole(), episodes=3)) or serve it by import path (python -m rlmesh.serve --env environment:CartPole, with the class saved in environment.py). This is the class structure used by catalog environments.
serve() builds the environment and blocks while clients use the endpoint. A client in another process connects with RemoteEnv and runs the usual reset and step loop. See Connect a Client for that side.
Add a model-facing contract when needed
The factory’s optional tags attribute names the roles of observation and action fields. Declare it when a model needs RLMesh to adapt environment-specific keys, layouts, or encodings to its own input. The factory attaches those tags to every environment it builds; a model’s ModelSpec can then resolve against them. The Adapters guide shows both declarations together.
A factory can also declare construction parameters, enumerate named task variants, and publish a description for a catalog without starting the simulator. The Environment Reference owns the exact hooks, parameter and variant rules, describe() format, and container entrypoint. For a complete container example, see Bring Your Own Container.