LangGraph Agent + OpenSandbox Example
Integrate LangGraph with OpenSandbox using a graph-driven control flow. The example uses explicit state machine nodes to create, prepare, run, inspect, and clean up a sandbox, plus a decision node to retry with a fallback command if the run step fails.
Start OpenSandbox server [local]
Pre-pull the code-interpreter image (includes Python):
shell
docker pull sandbox-registry.cn-zhangjiakou.cr.aliyuncs.com/opensandbox/code-interpreter:v1.0.1
# use docker hub
# docker pull opensandbox/code-interpreter:v1.0.1Start the local OpenSandbox server, logs will be visible in the terminal:
shell
uv pip install opensandbox-server
opensandbox-server init-config ~/.sandbox.toml --example docker
opensandbox-serverRun the example
shell
# Install OpenSandbox + LangGraph deps
uv pip install opensandbox langgraph langchain-anthropic
# Run the example (requires SANDBOX_DOMAIN / SANDBOX_API_KEY / ANTHROPIC_API_KEY)
uv run python examples/langgraph/main.pyThe workflow writes files, executes a job, retries with a fallback command on failure (default python vs python3), then summarizes results with Claude and cleans up the sandbox instance.

Environment Variables
SANDBOX_DOMAIN: Sandbox service address (default:localhost:8080)SANDBOX_API_KEY: API key if your server requires authentication (optional for local)SANDBOX_IMAGE: Sandbox image to use (default:sandbox-registry.cn-zhangjiakou.cr.aliyuncs.com/opensandbox/code-interpreter:v1.0.1)ANTHROPIC_API_KEY: Your Anthropic API key (required ifANTHROPIC_AUTH_TOKENis unset)ANTHROPIC_AUTH_TOKEN: Alternate Anthropic auth token (usesAuthorizationheader)ANTHROPIC_API_KEYandANTHROPIC_AUTH_TOKENshould not be set togetherANTHROPIC_BASE_URL: Anthropic API endpoint override (optional)ANTHROPIC_MODEL: Model to use (default:claude-3-5-sonnet-latest)
References
- LangGraph - Agent workflow framework
This page is sourced from:
examples/langgraph/README.md