§ 00Integrations · Claude Managed Agents

Claude Managed Agents quickstart: a server that keeps its files and a live URL

Claude Managed Agents can call any remote MCP server. Point one at Server4Agent and your agent gets a server of its own: a project that keeps its files from one session to the next, and a deploy tool that puts what it built at a live URL. Nothing to install on our side, just an API key.

§ 01Quickstart

One script, from agent to live URL

It stores your Server4Agent key in a vault, creates an agent with the Server4Agent tools, starts a session, and asks for a page to be built and deployed. The agent replies with the URL.

  • ▸Access to Claude Managed Agents and an Anthropic API key. Anthropic bills the agent's tokens and session time.
  • ▸A Server4Agent account and an API key from the API Keys page. The free plan is enough for this example.
  • ▸Python 3.10 or newer and the anthropic package.
quickstart.py
"""Claude Managed Agents + Server4Agent over MCP.

Gives a Claude managed agent the Server4Agent MCP server, then asks it to build
a page and put it online. The agent writes the files into a Server4Agent
project and deploys it, so the result has a live URL and is still there for
the next session.

Run:
    pip install anthropic
    export ANTHROPIC_API_KEY=...        # console.anthropic.com
    export S4A_API_KEY=sk_live_...      # server4agent.com, API Keys
    python quickstart.py

Config follows Anthropic's MCP connector, vaults and permission policy docs:
https://platform.claude.com/docs/en/managed-agents/mcp-connector
https://platform.claude.com/docs/en/managed-agents/vaults
https://platform.claude.com/docs/en/managed-agents/permission-policies
"""

import os

from anthropic import Anthropic

S4A_MCP_URL = "https://mcp.server4agent.com"

# Tools that remove things. Left off so nothing the agent does can delete a
# server, project, file, secret, domain or connected sandbox. Turn one back on
# when you need it.
REMOVE_TOOLS = [
    "delete_server",
    "delete_project",
    "cleanup_project",
    "delete_file",
    "delete_secret",
    "remove_domain",
    "disconnect_agent_environment",
]

TASK = (
    "Use Server4Agent to put a one-page site online: a page that says hello "
    "and shows today's date. Reuse a running server if one has room, create a "
    "project, write the files, start the app, deploy it, and reply with the URL."
)

client = Anthropic()  # reads ANTHROPIC_API_KEY

# 1. The Server4Agent key goes in a vault, keyed by the MCP server URL. The
#    agent definition below never holds it.
vault = client.beta.vaults.create(display_name="Server4Agent")
client.beta.vaults.credentials.create(
    vault_id=vault.id,
    display_name="Server4Agent API key",
    auth={
        "type": "static_bearer",
        "mcp_server_url": S4A_MCP_URL,
        "token": os.environ["S4A_API_KEY"],
    },
)

# 2. The agent declares the server by URL and gets its tools as a toolset.
#    MCP toolsets ask before every call by default; this one allows them,
#    with the removal tools switched off.
agent = client.beta.agents.create(
    name="Server4Agent builder",
    model="claude-sonnet-5-5",
    system=(
        "You build and host things with the Server4Agent tools. Projects are "
        "private until you deploy them. Always reply with the live URL."
    ),
    mcp_servers=[{"type": "url", "name": "server4agent", "url": S4A_MCP_URL}],
    tools=[
        {"type": "agent_toolset_20260401"},
        {
            "type": "mcp_toolset",
            "mcp_server_name": "server4agent",
            "default_config": {"permission_policy": {"type": "always_allow"}},
            "configs": [{"name": name, "enabled": False} for name in REMOVE_TOOLS],
        },
    ],
)

# 3. Limited networking: the MCP server is allowed, and so are deployed apps,
#    so the agent can check its own URL from the sandbox.
environment = client.beta.environments.create(
    name="server4agent-quickstart",
    config={
        "type": "cloud",
        "networking": {
            "type": "limited",
            "allow_mcp_servers": True,
            "allowed_hosts": ["*.apps.server4agent.com"],
        },
    },
)

# 4. The session brings the vault, which is where the key comes from.
session = client.beta.sessions.create(
    agent=agent.id,
    environment_id=environment.id,
    vault_ids=[vault.id],
    title="Server4Agent quickstart",
)
print(f"Session {session.id}")

with client.beta.sessions.events.stream(session.id) as stream:
    client.beta.sessions.events.send(
        session.id,
        events=[{"type": "user.message", "content": [{"type": "text", "text": TASK}]}],
    )
    for event in stream:
        match event.type:
            case "agent.message":
                for block in event.content:
                    if block.type == "text":
                        print(block.text, end="")
            case "agent.mcp_tool_use":
                print(f"\n[server4agent: {event.name}]")
            case "session.error":
                print(f"\n[error: {event.error.type}: {getattr(event.error, 'message', '')}]")
            case "session.status_idle":
                print(f"\n\nDone ({event.stop_reason.type}).")
                break
terminal
pip install anthropic
export ANTHROPIC_API_KEY=...        # from the Claude Console
export S4A_API_KEY=sk_live_...      # from Server4Agent, API Keys
python quickstart.py

The script creates a vault, an agent and an environment each time it runs. In your own app, create them once and keep their IDs. Everything the agent builds is a real project on your account, private until it deploys.

§ 02The config

What each part does

Every value is from Anthropic's docs as of November 24, 2026. The server URL is the only Server4Agent setting.

1. The key goes in a vault

A static_bearer credential holds your Server4Agent API key, keyed by https://mcp.server4agent.com. Claude sends it as a bearer token whenever the agent connects to that URL. The agent definition never holds the key, so one agent can serve many users, each with their own vault.

2. The agent declares the server

mcp_servers names the server by URL, and an mcp_toolset entry with the same name gives the agent its tools. MCP toolsets ask for approval before every call by default. The example allows them, and switches off the seven tools that remove things.

3. The environment lets it through

With limited networking, a session is refused unless the MCP server's host is allowed, so allow_mcp_servers is on. apps.server4agent.com subdomains are allowed too, so the agent can open the URL it deployed and check it.

4. The session brings the vault

vault_ids is where the key comes from. If the key is wrong or missing, the session emits a session.error of type mcp_authentication_failed_error and keeps running without the tools.

§ 03Next session

A fresh session finds the same project

A managed agent's own sandbox does not carry files from one session to the next. The Server4Agent project does, at the same URL, so a later session can pick the work up where the last one left it.

next_session.py
session = client.beta.sessions.create(
    agent=agent.id,
    environment_id=environment.id,
    vault_ids=[vault.id],
    title="Change yesterday's page",
)
# Then send, as before:
# "Open the Server4Agent project you deployed yesterday, add a contact
#  section, and deploy it again. Keep the same URL."
§ 04FAQ

Good to know

Why connect a managed agent to Server4Agent?

A Claude managed agent works in a sandbox that belongs to one session. Through Server4Agent it writes into a project on a server in your account: the files are still there next session, and a deploy puts the result at a live URL that stays up after the session ends.

Does the agent still use its own sandbox?

Yes, for its own bash and file tools. Anything it should keep, or put online, it writes through the Server4Agent tools. You can drop agent_toolset_20260401 from the example if you want Server4Agent to be its only workspace.

Should every tool be allowed without asking?

Decide per tool. Set a tool's permission_policy to always_ask and the session pauses until your app sends a user.tool_confirmation that allows or denies the call. The example leaves the removal tools off entirely rather than asking.

Can I limit what the key reaches?

Yes. A Server4Agent API key can be scoped to particular servers or projects, so an agent working for one customer cannot see another's. The account's monthly budget cap applies to every key, and the agent cannot raise it.

Who pays for what?

Anthropic bills the model tokens and session time. Server4Agent bills the servers and anything its own build agent does, within your plan. Claude's session budgets can cap the Anthropic side per session.

What if a tool returns a lot of output?

Claude writes any MCP tool result over 100,000 characters to a file in the sandbox and gives the model a preview. Ask for logs or file contents in smaller pieces when you can.

§ 05Sources

Anthropic's docs this follows

Read on November 24, 2026. Managed Agents is in beta, so check them if a field has moved.

Building on OpenAI instead? Follow the OpenAI Agents API quickstart. Every Server4Agent tool is listed in the MCP docs.