A Server4Agent project can now be the self-hosted sandbox for an agent you run on Claude Managed Agents. You connect the environment's key to a project, and from then on every session in that environment runs its commands and file edits in the project's folder, on your server. Nothing in your app has to change: sessions are picked up on their own.
Before this, a Claude agent could reach Server4Agent only through its MCP tools, while its own shell ran in Anthropic's sandbox. Now the shell and the project share one folder, and nobody has to start anything when a session begins.
This post covers how to connect a Claude Managed Agents environment, what happens when a session starts, and what to know before you rely on it. The OpenAI Agents API works differently, because your app starts each session's executor itself, so it has its own post.
Quick answer
Create a self-hosted environment and an environment key in the Claude Console. Then, on the project's Settings tab, open Advanced, choose Connect under Managed agents, pick Claude Managed Agents and paste the environment id and the key. Every session in that environment is then picked up on its own, and its tool calls run in the project's folder. The server can sleep between sessions and wakes when one starts.
Key takeaways
- A project can act as the self-hosted sandbox for a Claude Managed Agents environment, with no change to how your app starts sessions.
- The agent's commands and file edits happen in the project's folder, next to the app you deploy from it.
- You connect it on the dashboard, over REST, or with the
connect_agent_environmentMCP tool. - Environment keys are stored encrypted, the same way project secrets are, and are never shown again. Account API keys are refused.
- The server does not have to stay on. It sleeps between sessions and wakes when a session starts.
Why run the sandbox on your own project
Claude Managed Agents lets you choose where an agent's tools run. Its own hosted sandbox is the default, and a self-hosted environment is the other option: a worker you run picks up the session's tool calls and executes them on your machines. Plenty of providers already plug into that option, and some of them, such as Daytona and E2B, also keep a sandbox's files between sessions.
What a Server4Agent project adds is that the sandbox is the project itself. The files the agent writes are the project's files. A package it installs is installed where the app runs. When it is done, the same project can be deployed at its URL, kept private, or shared with your team, without copying anything out of a sandbox first.
Connect Claude Managed Agents
- In the Claude Console, create a self-hosted environment, then create an environment key for it. The environment key is separate from your Claude API key and only connects workers to that environment.
- In Server4Agent, open the project's Settings tab, open Advanced, and choose Connect under Managed agents. Pick Claude Managed Agents and paste the environment id and the environment key.
- Start a session in that environment the way you normally do. There is nothing else to call.
From there, Server4Agent watches the environment for you, so your server can sleep while nothing is happening. When a session arrives, it wakes the server, installs the ant command line tool on it the first time, and runs the environment worker in the project's folder. The worker stops after 10 minutes without work, and the server can go back to sleep after that.
What happens to your key
The environment key can connect a worker to your environment, so it is handled like any other secret:
- It is stored encrypted, the way project secrets are, and never returned by the dashboard, the API or the MCP tools. You see its last four characters so you can tell keys apart.
- Only the worker that runs sessions opens it. It hands the key to the session through a private file on the server, never on a command line.
- Account API keys are refused. Paste the environment key the Console gives you for this, not the key your app uses to call the model.
- If a key stops working, the connection shows an error and Server4Agent backs off until you replace the key.
To stop, choose Disconnect in the same place, or call disconnect_agent_environment. Server4Agent stops picking up sessions for that environment and deletes the stored key.
What to know before you rely on it
- Beta on Claude's side. Claude's docs mark self-hosted environments as beta, so the worker commands Server4Agent runs may change with them.
- One environment per project. Each project can have one Claude Managed Agents environment. Connecting again replaces the key.
- Sessions are capped. Each server and the whole service run a limited number of sessions at once, so a burst of sessions can wait.
- A paused server does not start sessions. While the project's server is paused, new sessions are refused until you resume it.
FAQ
What is a self-hosted sandbox for Claude Managed Agents?
It is an environment where the agent's tool calls, such as shell commands and file edits, run on machines you choose instead of in the platform's own sandbox. The model still runs on the platform. A worker you run picks up the tool calls and sends back the results.
Does my Server4Agent server have to stay on?
No. Server4Agent watches for Claude sessions without waking your server, wakes it when a session starts, and lets it sleep again once the session has gone quiet.
Where do the agent's files end up?
In the project's folder on your server, alongside everything else in the project. You can read them, run them, or deploy the project at its URL afterwards.
Can I use the same project for both platforms?
Yes. A project can have one Claude Managed Agents connection and one OpenAI Agents API connection at the same time. The OpenAI side is covered in its own post.
Is my environment key safe?
It is stored encrypted and never shown again after you paste it. Only the process that runs a session reads it, through a private file on the server. Account API keys are refused, so the key on file is the one made for connecting environments.
Related reading
- OpenAI Agents API sessions you start in your project with one call
- Why AI agents need persistent workspaces
- Give your AI agent its own server with one MCP call
- What is an AI agent server?
- Claude Managed Agents quickstart
- MCP tool reference