Skip to content

Feature Request: setup_commands / init hooks for Managed Agents environments #984

@thecmdrunner

Description

@thecmdrunner

What

Add a setup_commands field to the environment config (or a post_create_command on session create) that runs arbitrary shell commands in the container after provisioning but before the agent starts inference.

const environment = await client.beta.environments.create({
  name: "my-env",
  config: {
    type: "cloud",
    networking: { type: "unrestricted" },
    packages: { pip: ["pandas"] },
    setup_commands: [
      "chmod +x /workspace/setup.sh && /workspace/setup.sh",
      "mkdir -p /workspace/data && echo 'ready' > /workspace/data/.initialized",
    ],
  },
});

Or alternatively, a session-level hook that runs after resources are mounted:

const session = await client.beta.sessions.create({
  agent: agent.id,
  environment_id: environment.id,
  resources: [
    { type: "file", file_id: script.id, mount_path: "/workspace/setup.sh" },
  ],
  post_create_command: "bash /workspace/setup.sh",
});

Why

Currently the only way to execute commands in a Managed Agents container is through agent tool calls, which means every shell command routes through model inference. For predictable, repeatable setup tasks — provisioning directories, running init scripts, seeding databases, setting file permissions — this wastes tokens and compute on something that needs zero intelligence.

The existing packages field solves package installation beautifully (zero inference cost, cached across sessions). But there's a gap between "install packages" and "agent starts working" where users often need deterministic setup that doesn't belong in the agent loop.

Use Cases

  1. Run a mounted init script — Upload a shell script via file resources, need it executed before the agent starts. Currently requires burning inference tokens on a bash tool call for something completely deterministic.

  2. Seed a database — Pre-populate a SQLite DB or run SQL migrations so the agent starts with data already in place, rather than asking it to run the migration.

  3. Set file permissions — Files mount read-only. Copying them to writable paths and chmod +x-ing scripts requires agent inference for a mechanical task.

  4. Generate config files from templates — Render environment-specific configs (e.g., envsubst a template) before the agent touches them.

  5. Clone private registries / install custom packages — Run pip install -e ./mounted-repo or npm link on a mounted package that isn't on a public registry.

  6. CI/CD-style provisioning — Teams building platforms on top of Managed Agents need deterministic, auditable setup steps that aren't subject to model interpretation. Similar to postCreateCommand in dev containers.

Current Workaround

System prompt instruction ("run bash /workspace/setup.sh before anything else") + cheapest model. Works, but:

  • Still costs inference tokens for a zero-intelligence task
  • Non-deterministic — the agent might explain what it's doing, skip the step, or modify the command
  • Can't enforce ordering guarantees (setup completes before first real task)

This is an API-level feature request filed here since this is the SDK I'm using. Happy to have it redirected if there's a better channel.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions