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
-
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.
-
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.
-
Set file permissions — Files mount read-only. Copying them to writable paths and chmod +x-ing scripts requires agent inference for a mechanical task.
-
Generate config files from templates — Render environment-specific configs (e.g., envsubst a template) before the agent touches them.
-
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.
-
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.
What
Add a
setup_commandsfield to the environment config (or apost_create_commandon session create) that runs arbitrary shell commands in the container after provisioning but before the agent starts inference.Or alternatively, a session-level hook that runs after resources are mounted:
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
packagesfield 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
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
bashtool call for something completely deterministic.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.
Set file permissions — Files mount read-only. Copying them to writable paths and
chmod +x-ing scripts requires agent inference for a mechanical task.Generate config files from templates — Render environment-specific configs (e.g.,
envsubsta template) before the agent touches them.Clone private registries / install custom packages — Run
pip install -e ./mounted-repoornpm linkon a mounted package that isn't on a public registry.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
postCreateCommandin dev containers.Current Workaround
System prompt instruction ("run
bash /workspace/setup.shbefore anything else") + cheapest model. Works, but: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.