Skip to content

Sandbox.create(config=Config(...)) still raises "account id is not set" unless AGENTRUN_ACCOUNT_ID is also set in env #75

@youyuanrsq

Description

@youyuanrsq

Describe the bug
When using Sandbox.create(..., config=Config(...)) in agentrun-sdk==0.0.27, the SDK still raises:

ValueError: account id is not set, please add AGENTRUN_ACCOUNT_ID env variable or set it in code.

even though Config(account_id=...) is explicitly constructed with a non-empty account_id and passed into Sandbox.create.

From the stack trace, the failure happens inside the SDK’s internal config/data-api path:

  • agentrun.utils.data_api.DataApi.get_base_url()
  • agentrun.utils.config.Config.get_data_endpoint()
  • agentrun.utils.config.Config.get_account_id()

This suggests the internal request path is relying on an internal self.config state that does not consistently reflect the config object passed into Sandbox.create(...).

In practice, the call succeeds only after mirroring the same credentials into process environment variables such as AGENTRUN_ACCOUNT_ID, which should not be necessary if explicit Config(...) arguments are honored consistently.

To Reproduce

  1. Install agentrun-sdk==0.0.27.
  2. In Python, construct a Config object with explicit credentials and account ID:
from agentrun.utils.config import Config
from agentrun.sandbox import Sandbox, TemplateType

config = Config(
    account_id="your-account-id",
    access_key_id="your-ak",
    access_key_secret="your-sk",
    region_id="cn-hangzhou",
)
  1. Call Sandbox.create(...) with that config:
sandbox = Sandbox.create(
    template_type=TemplateType.CODE_INTERPRETER,
    template_name="your-template-name",
    sandbox_idle_timeout_seconds=1800,
    config=config,
)
  1. Ensure AGENTRUN_ACCOUNT_ID is not set in the process environment.
  2. Observe the error:
ValueError: account id is not set, please add AGENTRUN_ACCOUNT_ID env variable or set it in code.

In our integration, logging right before the SDK call confirms that the resolved account_id is non-empty before constructing Config(...).

Expected behavior
If Sandbox.create(..., config=Config(account_id=...)) is called with a valid non-empty account_id, the SDK should use that value consistently across all internal request paths.

The caller should not also need to set AGENTRUN_ACCOUNT_ID in environment variables for the same request to work.

Screenshots
Not applicable.

Desktop (please complete the following information):

  • OS: Linux (containerized runtime)
  • Browser: N/A
  • Version: N/A

Smartphone (please complete the following information):

  • Device: N/A
  • OS: N/A
  • Browser: N/A
  • Version: N/A

Additional context
SDK version:

  • agentrun-sdk==0.0.27

Relevant stack trace:

File "/app/app/core/sandbox/client.py", line 95, in create_sandbox
  sandbox = Sandbox.create(
File "/app/.venv/lib/python3.12/site-packages/agentrun/sandbox/sandbox.py", line 329, in create
  base_sandbox = cls.__get_client().create_sandbox(
File "/app/.venv/lib/python3.12/site-packages/agentrun/sandbox/client.py", line 603, in create_sandbox
  result = self.__sandbox_data_api.create_sandbox(
File "/app/.venv/lib/python3.12/site-packages/agentrun/sandbox/api/sandbox_data.py", line 130, in create_sandbox
  return self.post("/", data=data, config=config)
File "/app/.venv/lib/python3.12/site-packages/agentrun/utils/data_api.py", line 635, in post
  self.with_path(path, query=query),
File "/app/.venv/lib/python3.12/site-packages/agentrun/utils/data_api.py", line 127, in with_path
  self.get_base_url(),
File "/app/.venv/lib/python3.12/site-packages/agentrun/utils/data_api.py", line 97, in get_base_url
  return self.config.get_data_endpoint()
File "/app/.venv/lib/python3.12/site-packages/agentrun/utils/config.py", line 252, in get_data_endpoint
  return f"https://{self.get_account_id()}.agentrun-data.{self.get_region_id()}.aliyuncs.com"
File "/app/.venv/lib/python3.12/site-packages/agentrun/utils/config.py", line 214, in get_account_id
  raise ValueError(
ValueError: account id is not set, please add AGENTRUN_ACCOUNT_ID env variable or set it in code.

Additional observed behavior:

  • We confirmed in application logs that the account_id was present immediately before constructing the SDK Config(...).
  • As a workaround, exporting the same values into environment variables (AGENTRUN_ACCOUNT_ID, etc.) before calling the SDK makes the same request succeed.
  • That strongly suggests the internal request path does not consistently use the explicitly passed config object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions