@@ -303,6 +303,9 @@ def remote(
303303 """
304304
305305 def _remote (func ):
306+
307+ if job_conda_env :
308+ RemoteExecutor ._validate_env_name (job_conda_env )
306309
307310 job_settings = _JobSettings (
308311 dependencies = dependencies ,
@@ -774,6 +777,9 @@ def __init__(
774777 + "without spark_config or use_torchrun or use_mpirun. "
775778 + "Please provide instance_count = 1"
776779 )
780+
781+ if job_conda_env :
782+ self ._validate_env_name (job_conda_env )
777783
778784 self .job_settings = _JobSettings (
779785 dependencies = dependencies ,
@@ -951,6 +957,25 @@ def _validate_submit_args(func, *args, **kwargs):
951957 + f"{ 'arguments' if len (missing_kwargs ) > 1 else 'argument' } : "
952958 + f"{ missing_kwargs_string } "
953959 )
960+
961+ @staticmethod
962+ def _validate_env_name (env_name : str ) -> None :
963+ """Validate conda environment name to prevent command injection.
964+
965+ Args:
966+ env_name (str): The environment name to validate
967+
968+ Raises:
969+ ValueError: If the environment name contains invalid characters
970+ """
971+
972+ # Allow only alphanumeric, underscore, and hyphen
973+ import re
974+ if not re .match (r'^[a-zA-Z0-9_-]+$' , env_name ):
975+ raise ValueError (
976+ f"Invalid environment name '{ env_name } '. "
977+ "Only alphanumeric characters, underscores, and hyphens are allowed."
978+ )
954979
955980
956981class Future (object ):
0 commit comments