SandboxesOpenAI Agents SDK

OpenAI Agents SDK sandbox: run a SandboxAgent in Lizard Sandboxes

An OpenAI Agents SDK sandbox is the machine where a SandboxAgent runs its shell and file tools. With lizard-sdk[openai-agents] that machine is a Lizard sandbox: LizardSandboxClient gives each run a Firecracker microVM with its own kernel, which the runner creates when the run starts and deletes when it ends.

To use Lizard Sandboxes as the sandbox provider for the OpenAI Agents SDK in Python, install the extra and pass the client to SandboxRunConfig:

pip install "lizard-sdk[openai-agents]"

Test status: on 2026-12-02 we ran the scripted-model example, the own-session example and the resume example on this page against Small sandboxes with lizard-sdk 1.0.25 and openai-agents 0.26.2 on Python 3.11. The first example calls an OpenAI model, and we did not run it with a model key for this page.

Install and keys

The extra needs Python 3.10 or later and installs openai-agents 0.26 next to Lizard SDK. Set three variables:

export LIZARD_API_KEY="<your-api-key>"
export LIZARD_PROJECT="my-project"
export OPENAI_API_KEY="<your-openai-key>"
  • LIZARD_API_KEY: create a key in Settings → API keys or with lizard keys create <name>. You can pass api_key= to LizardSandboxClient instead. The key stays on the client; options and saved session state never hold it.
  • LIZARD_PROJECT: the ID, slug or name of the project the sandboxes belong to. You can pass project= to the client instead.
  • OPENAI_API_KEY: the Agents SDK reads it in your process to call the model. The sandbox never receives it, and the provider uses no credential from lizard agents.

You need Lizard Pro or the 7-day Pro trial (card required); see billing.

Run a SandboxAgent

import asyncio
from agents import RunConfig, Runner
from agents.sandbox import SandboxAgent, SandboxRunConfig
from agents.sandbox.capabilities import Shell
from lizard.openai_agents import LizardSandboxClient, LizardSandboxClientOptions
 
agent = SandboxAgent(name="Coder", instructions="Answer with the shell.", capabilities=[Shell()])
run_config = RunConfig(
    sandbox=SandboxRunConfig(
        client=LizardSandboxClient(),
        options=LizardSandboxClientOptions(template="base", size="small"),
    ),
)
result = asyncio.run(Runner.run(agent, "Which Linux kernel runs here?", run_config=run_config))
print(result.final_output)

The runner creates one Small sandbox from the base template, runs the agent’s commands in it and deletes it when the run ends. Importing lizard.openai_agents registers the lizard options and session state types with the Agents SDK, so import it in every process that resumes a saved run.

Options

LizardSandboxClientOptions takes three fields. Any other field is refused.

OptionDefaultWhat it sets
template"base"The sandbox template; see runtime and templates.
sizethe platform default"nano", "mini", "small", "medium", "large" or "big".
timeout3600The sandbox lifetime in seconds. 0 sets no deadline on paid plans.
  • size="small" is 2 vCPU and 4 GB of RAM at $0.0162 an hour. With no size, a sandbox is Medium (4 vCPU, 8 GB, $0.0324 an hour) after the first payment and Small on the trial. See sizes and prices for the other sizes and the templates each one starts from.
  • timeout is a deadline for the whole sandbox, and commands do not reset it. On the trial a sandbox lives 1 hour at most: a longer timeout is refused, and 0 gets 1 hour. Runs longer than 1 hour need a paid plan.
  • The trial runs 1 Small sandbox at a time, so it runs one Small agent run at a time.

Lifecycle and cost

A sandbox the runner creates belongs to the run: the runner deletes it when the run ends. Billing is per second by size from create to delete, idle time included, so a 10-minute run on Small costs about $0.0027 (600 s × $0.0162 / 3,600 s).

To keep one sandbox across several runs, create the session yourself and pass it as session:

import asyncio
from agents import RunConfig, Runner
from agents.sandbox import SandboxAgent, SandboxRunConfig
from agents.sandbox.capabilities import Shell
from lizard.openai_agents import LizardSandboxClient, LizardSandboxClientOptions
 
agent = SandboxAgent(name="Coder", instructions="Answer with the shell.", capabilities=[Shell()])
 
async def main():
    client = LizardSandboxClient()
    session = await client.create(
        options=LizardSandboxClientOptions(template="base", size="small", timeout=1800),
    )
    try:
        async with session:
            run_config = RunConfig(sandbox=SandboxRunConfig(session=session))
            await Runner.run(agent, "Write the plan to plan.md.", run_config=run_config)
            await Runner.run(agent, "Read plan.md and do step one.", run_config=run_config)
    finally:
        await client.delete(session)
 
asyncio.run(main())

Both runs work in the same sandbox, so the second one sees the files of the first. Leaving the async with block deletes the sandbox. client.delete(session) in finally deletes it when something fails before that, and calling it twice is safe. If your process dies before either runs, the sandbox lives until its timeout, which is the reason to set one.

Resume a saved run

A session’s state says which sandbox it used and how to create a like one. It holds no credentials. Save it as JSON, then pass it to a later run as session_state:

import json
 
# First process, inside an async function: a session from client.create().
saved = json.dumps(client.serialize_session_state(session.state))
 
# Later process:
client = LizardSandboxClient()
state = client.deserialize_session_state(json.loads(saved))
run_config = RunConfig(sandbox=SandboxRunConfig(client=client, session_state=state))
result = await Runner.run(agent, "Continue from plan.md.", run_config=run_config)

What the client does depends on the state of the saved sandbox:

Saved sandboxWhat resume does
RunningReattaches to it. Files and running processes are as you left them.
PausedResumes it and waits up to 2 minutes for it to run. Files are kept. Processes are not: the sandbox boots fresh.
Deleted or past its lifetimeCreates a new sandbox with the same template, size and timeout. The runner restores the workspace from the run’s snapshot if the run kept one.

A paused sandbox has no compute charge; its used disk bills at $0.14 per GB-month until you resume or delete it. Wait until the sandbox’s status is paused before you resume it. While it is still pausing, the client treats it as gone and creates a new sandbox.

The resumed run owns the sandbox and deletes it when the run ends.

Workspace snapshots

When the Agents SDK persists a workspace, the client archives the manifest root (/workspace by default) as tar inside the sandbox and reads the archive back. Paths the SDK marks to skip are left out. Restoring unpacks the archive into the manifest root of the new sandbox, after a check for unsafe archive members.

Limits

  • Commands run as root.
  • A command runs for 600 seconds at most. A command with no timeout gets 600 seconds, and a longer timeout is cut to 600. Start longer work in the background and poll for it.
  • A command returns at most 512 KiB of standard output. Write larger results to a file and read the file.
  • Files of any size move through read and write: the client sends files above 8 MiB in 8 MiB slices and reads files above 15 MiB the same way.

What is refused

The client raises ConfigurationError instead of running these some other way:

  • PTY sessions;
  • exposed ports;
  • manifest mounts;
  • manifest users and groups;
  • run_as, or a user on a command, read or write.

To reach a port in a sandbox, use preview URLs from Lizard SDK or Lizard CLI.

Test without an OpenAI key

The Agents SDK ships ScriptedModel, which plays back tool calls you write. This runs one command in a real sandbox and needs only the two Lizard variables:

import asyncio
from agents import RunConfig, Runner
from agents.sandbox import SandboxAgent, SandboxRunConfig
from agents.sandbox.capabilities import Shell
from agents.testing import ScriptedModel, assistant_message, function_call
from lizard.openai_agents import LizardSandboxClient, LizardSandboxClientOptions
 
model = ScriptedModel([
    [function_call("exec_command", {"cmd": "uname -sr && whoami && nproc"}, call_id="first")],
    [assistant_message("Done.")],
])
agent = SandboxAgent(name="Scripted", model=model, capabilities=[Shell()])
run_config = RunConfig(
    tracing_disabled=True,
    sandbox=SandboxRunConfig(
        client=LizardSandboxClient(),
        options=LizardSandboxClientOptions(template="base", size="small", timeout=600),
    ),
)
result = asyncio.run(Runner.run(agent, "Run the command.", run_config=run_config))
model.assert_complete()
for item in result.new_items:
    if item.type == "tool_call_output_item":
        print(item.output)

In our run the command printed Linux 6.1.177+, root and 2, and the whole script took about 20 seconds.

Supported versions

lizard-sdk[openai-agents] pins openai-agents>=0.26.0,<0.27. The provider builds on internal hooks of the Agents SDK, so each new minor version is tested before the pin moves. The provider is Python only and ships in lizard-sdk from 1.0.25.

See also

Updated