Superserve

Run agent-generated code in an isolated Superserve cloud sandbox.

Superserve provides isolated cloud sandboxes (Firecracker microVMs) for running AI-generated code. The sandbox persists across tool calls, so files your agent writes and packages it installs remain available. Every tool has a sync and an async variant, so the toolkit works with both agent.run() and agent.arun().

Prerequisites

The following example requires the superserve and openai packages:

uv pip install agno superserve openai

You will also need a Superserve API key. You can get it from superserve.ai:

export SUPERSERVE_API_KEY=ss_live_...

Set OPENAI_API_KEY in the host terminal for the agent model. A secret bound inside the Superserve sandbox does not configure that host process.

Example

This example creates an agent that writes and executes code in a Superserve sandbox:

from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.tools.superserve import SuperserveTools

agent = Agent(
    name="Coding Agent with Superserve tools",
    model=OpenAIResponses(id="gpt-5.5"),
    tools=[SuperserveTools(timeout=600)],
    markdown=True,
    instructions=[
        "You are an expert at writing and executing code in a secure Superserve sandbox.",
        "Your primary purpose is to:",
        "1. Write clear, efficient code based on user requests",
        "2. ALWAYS execute the code in the sandbox using run_python_code or run_command",
        "3. Show the actual execution results to the user",
        "4. Provide explanations of how the code works and what the output means",
        "Guidelines:",
        "- NEVER just provide code without executing it",
        "- Install missing packages when needed using run_command, for example pip install <package>",
        "- Use file operations (create_file, read_file, list_files) when working with scripts",
        "- Always show both the code AND the execution output",
        "- Handle errors gracefully and explain any issues encountered",
    ],
)

agent.print_response(
    "Write Python code to generate the first 10 Fibonacci numbers and calculate their sum and average"
)

Sandbox Reuse

With persistent=True (the default), the sandbox ID is stored in the agent's session state. The same sandbox is reused across tool calls and across runs in the same session. Pass sandbox_id to connect to a specific existing sandbox instead of creating a new one.

Sandboxes are created from the superserve/code-interpreter template by default, which ships with Python 3.11 and pip. Override it for other runtimes:

SuperserveTools(template="superserve/node-22")

Secrets

Bind team secrets to the sandbox without exposing the real credential. The sandbox sees a proxy token; the real value is swapped in only for outbound requests to the secret's allowed hosts:

SuperserveTools(secrets={"OPENAI_API_KEY": "openai-prod"})

Toolkit Params

ParameterTypeDefaultDescription
api_keyOptional[str]NoneSuperserve API key. If not provided, uses the SUPERSERVE_API_KEY env var
base_urlOptional[str]NoneOverride the control-plane base URL. If not provided, uses the SUPERSERVE_BASE_URL env var or the SDK default
sandbox_idOptional[str]NoneConnect to an existing sandbox instead of creating a new one
templateOptional[str]NoneTemplate to create the sandbox from. Defaults to superserve/code-interpreter
timeoutint300Active-session time limit in seconds before auto-pause; forwarded as timeout_seconds. Does not delete the sandbox.
auto_delete_secondsOptional[int]NoneDelete after this many continuously paused seconds. Resume cancels the countdown; a sandbox that never pauses is not auto-deleted.
command_timeoutint60Per-command timeout in seconds
output_directoryOptional[str]NoneHost directory that download_directory writes into. Defaults to the current working directory
metadataOptional[Dict[str, str]]NoneMetadata to attach to created sandboxes
env_varsOptional[Dict[str, str]]NoneEnvironment variables to set in created sandboxes
secretsOptional[Dict[str, str]]NoneTeam secrets to bind as {ENV_VAR: secret_name}. The sandbox sees a proxy token; the real credential never enters the sandbox
persistentboolTruePersist the sandbox ID in the agent's session state so the same sandbox is reused across runs
enable_run_python_codeboolTrueEnables the run_python_code tool
enable_run_commandboolTrueEnables the run_command tool
enable_create_fileboolTrueEnables the create_file tool
enable_read_fileboolTrueEnables the read_file tool
enable_list_filesboolTrueEnables the list_files tool
enable_delete_fileboolTrueEnables the delete_file tool
enable_download_directoryboolTrueEnables the download_directory tool
enable_get_sandbox_infoboolTrueEnables the get_sandbox_info tool
enable_list_sandboxesboolTrueEnables the list_sandboxes tool
enable_shutdown_sandboxboolTrueEnables the shutdown_sandbox tool
enable_shutdown_sandbox_by_idboolTrueEnables the shutdown_sandbox_by_id tool
enable_get_preview_urlboolTrueEnables the get_preview_url tool
enable_pause_sandboxboolFalseEnables the pause_sandbox tool
enable_resume_sandboxboolFalseEnables the resume_sandbox tool
enable_attach_secretboolFalseEnables the attach_secret tool
enable_detach_secretboolFalseEnables the detach_secret tool
allboolFalseEnables all tools, overriding the individual enable_* flags
instructionsOptional[str]NoneCustom instructions for using the Superserve tools
add_instructionsboolFalseWhether to add the instructions to the agent's system message

See Superserve lifecycle: the active-time timeout pauses the sandbox, then the separate auto-delete window can remove it. Each resume starts a fresh active-time window.

Toolkit Functions

FunctionDescription
run_python_codeExecute Python code in the sandbox and return stdout, stderr, and exit code
run_commandExecute a shell command in the sandbox
create_fileCreate or overwrite a file in the sandbox
read_fileRead a file's contents from the sandbox
list_filesList the contents of a directory in the sandbox
delete_fileDelete a file or directory in the sandbox
download_directoryDownload a directory from the sandbox as a zip archive saved locally
get_sandbox_infoGet the current sandbox's ID, name, status, and metadata
list_sandboxesList all sandboxes belonging to the team
shutdown_sandboxDelete the current sandbox and release its resources
shutdown_sandbox_by_idDelete a specific sandbox by its ID
get_preview_urlGet a public URL for a port exposed inside the sandbox
pause_sandboxPause the current sandbox to save resources (opt-in)
resume_sandboxResume the current paused sandbox (opt-in)
attach_secretBind a team secret to the sandbox under an environment variable (opt-in)
detach_secretRemove a secret binding from the sandbox (opt-in)

Each function has an async variant with the same tool name, used automatically with agent.arun().

Developer Resources