opsen documentation
Run agents on any runtime, with machine, model and tool spend under one task id.
What opsen does
Your agent runs on a sandbox — E2B, Modal, or your own machines — and its model calls are proxied through the same session that owns that sandbox. That is the whole design, and everything else follows from it.
Because opsen sits in both paths, one number covers the machine, the model and the tools your agent called:
{'total_usd': 0.41, 'compute_usd': 0.02, 'tokens_usd': 0.39,
'calls': 34, 'task_id': 'nightly-report'}And because the proxy is in the request path rather than reading a log afterwards, a budget is a refusal rather than an alert: an agent that would cross its cap is stopped mid-run, not discovered on an invoice.
Explore
Your agent needs no opsen code
The sandbox starts with the provider environment variables already set, so any SDK inside it routes through opsen with no configuration:
import anthropic
client = anthropic.Anthropic() # no api_key, no base_url
msg = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=400,
messages=[{"role": "user", "content": "hello"}],
)What is injected is a session token, not a provider key: scoped to one session, capped by that session's budget, dead when the session ends. A long-lived provider key inside a machine running generated code is the thing this design exists to avoid. See Environment for the full list.