Fix environment variable casting for dict and list types (#8494)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Graham Neubig
2025-05-20 17:47:07 -04:00
committed by GitHub
parent 40d9b0b13a
commit 6335afb010
3 changed files with 44 additions and 2 deletions

View File

@@ -37,7 +37,7 @@ class SandboxConfig(BaseModel):
Must be one of [1, 2, 4, 8]. Will only be used if the runtime is remote.
enable_gpu: Whether to enable GPU.
docker_runtime_kwargs: Additional keyword arguments to pass to the Docker runtime when running containers.
This should be a JSON string that will be parsed into a dictionary.
This should be a Python dictionary literal string that will be parsed into a dictionary.
trusted_dirs: List of directories that can be trusted to run the OpenHands CLI.
vscode_port: The port to use for VSCode. If None, a random port will be chosen.
This is useful when deploying OpenHands in a remote machine where you need to expose a specific port.

View File

@@ -91,7 +91,10 @@ def load_from_env(
cast_value = str(value).lower() in ['true', '1']
# parse dicts and lists like SANDBOX_RUNTIME_STARTUP_ENV_VARS and SANDBOX_RUNTIME_EXTRA_BUILD_ARGS │
elif (
get_origin(field_type) is dict or get_origin(field_type) is list
get_origin(field_type) is dict
or get_origin(field_type) is list
or field_type is dict
or field_type is list
):
cast_value = literal_eval(value)
else: