Skip to content

[databricks-openai] Add a sandbox example runner - #837

Merged
shaotong-db merged 3 commits into
databricks:mainfrom
HsingTang:hsingtang/openai-sandbox-example
Nov 2, 2026
Merged

shaotong-db merged 3 commits into
databricks:mainfrom
HsingTang:hsingtang/openai-sandbox-example

Conversation

@HsingTang

@HsingTang HsingTang commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What did you change, and why?

Add a runnable example, integrations/openai/examples/sandbox_runner.py, for the Databricks sandbox backend shipped in databricks-openai. It provisions a Databricks sandbox via DatabricksSandboxClient, runs a SandboxAgent's shell tool inside it against a Databricks model-serving endpoint, and prints the agent's answer - mirroring the hosted sandbox extension examples in the OpenAI Agents SDK.

The model is built with AsyncDatabricksOpenAI, so it authenticates to /serving-endpoints with a refreshing bearer token (PAT, OAuth, or M2M) and needs no OpenAI API key.

How do you know it works?

  • ruff check (imports/pyflakes) and ruff format --check clean.
  • Isaac Review: 0 findings (after addressing one auth finding - switched from a static config.token AsyncOpenAI client to AsyncDatabricksOpenAI).
  • Ran end to end against a live Databricks sandbox on a staging workspace: the agent executed the shell inside the sandbox and summarized the workspace, citing the manifest files.
assistant> I'll list the workspace, then read both files.
  [tool: exec_command] {"cmd": "ls -la", "workdir": "/home/sandbox-agent/agent-workspace"}
  [tool: exec_command] {"cmd": "cat README.md", "workdir": "/home/sandbox-agent/agent-workspace"}
  [tool: exec_command] {"cmd": "cat tasks.md", "workdir": "/home/sandbox-agent/agent-workspace"}

assistant> The workspace has two small files, `README.md` and `tasks.md`. I saw them with `ls -la` and read them with `cat README.md` and `cat tasks.md`. `README.md` titles it a "Databricks Demo Workspace" that validates the Databricks sandbox backend. `tasks.md` lists two steps: inspect the workspace files, then summarize the setup in two sentences.

HsingTang and others added 3 commits November 2, 2026 19:04
Add integrations/openai/examples/sandbox_runner.py: a runnable example that
provisions a Databricks sandbox via DatabricksSandboxClient, runs a SandboxAgent's
shell tool inside it against a Databricks model-serving endpoint, and prints the
agent's answer. Mirrors the hosted sandbox extension examples in the OpenAI Agents
SDK.

Co-authored-by: Isaac <no-reply@databricks.com>
Point the default question at explicit shell commands (ls -la, cat) so the
example demonstrates the sandbox command-execution path and surfaces it in the
output, while keeping the agent instructions general rather than hardcoding the
shell (future backends may add non-shell command APIs).

Co-authored-by: Isaac <no-reply@databricks.com>
Separate the assistant's text from the sandbox tool calls while streaming: print
each shell command on its own [tool: ...] line so the text before and after the
commands no longer runs together.

Co-authored-by: Isaac <no-reply@databricks.com>
@HsingTang
HsingTang marked this pull request as ready for review November 2, 2026 20:50
@shaotong-db
shaotong-db merged commit 4a0225a into databricks:main Nov 2, 2026
95 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants