What Is Open SWE in LangChain: The Open-Source Framework for Automated Coding Agents

Open SWE is LangChain's open-source framework for building internal coding agents that automate software development tasks like bug fixes, feature implementation, and pull request creation through isolated sandbox execution and curated toolsets.

Open SWE (Software Engineering) is a production-ready repository maintained by langchain-ai that packages the agent patterns used by companies like Stripe, Ramp, and Coinbase into a customizable, open-source stack. Unlike closed-source coding assistants, Open SWE provides transparent components built on the Deep Agents framework, enabling engineering teams to deploy autonomous agents that execute safely in isolated environments while adhering to repository-specific conventions defined in optional AGENTS.md files.

Core Architecture of Open SWE

Open SWE implements three foundational concepts that distinguish production-grade coding agents: the agent harness, isolated sandbox execution, and a curated toolset. These components work together in agent/server.py to create a deterministic, safe environment for automated code changes.

Agent Harness Built on Deep Agents

The agent harness does not fork existing bots but instead composes a new agent using create_deep_agent from the Deep Agents framework. In agent/server.py (line 249), the system calls this function to assemble the model, system prompt, tools, sandbox backend, and middleware into a unified worker. The system prompt itself is constructed in agent/prompt.py and can incorporate repository-wide conventions from an optional AGENTS.md file, ensuring the agent respects your team's specific coding standards and architectural decisions.

Isolated Sandbox Execution

Every task runs in its own cloud sandbox to guarantee safety and reproducibility. The SANDBOX_TYPE environment variable selects the provider—options include langsmith, daytona, modal, runloop, or local—and the factory function create_sandbox in agent/utils/sandbox.py (line 9) returns an object implementing the SandboxBackendProtocol. Before execution, the agent clones the target repository into the sandbox via _clone_or_pull_repo_in_sandbox in agent/server.py, ensuring all tool calls execute in an isolated environment that prevents accidental production changes.

Curated Development Toolset

Rather than accumulating unlimited tools, Open SWE provides a focused set exported from agent/tools/__init__.py covering common development actions:

  • execute – Run arbitrary shell commands in the sandbox
  • fetch_url – Retrieve web pages as markdown
  • http_request – Perform generic API calls
  • commit_and_open_pr – Stage changes, commit, and open draft GitHub PRs (implemented in agent/tools/commit_and_open_pr.py, line 27)
  • linear_comment and slack_thread_reply – Post updates to Linear tickets or Slack threads

This curation ensures the agent remains focused and reliable, avoiding the unpredictability of overly broad toolsets.

Deterministic Orchestration and Middleware

Open SWE layers deterministic middleware around the agent loop to ensure reliable execution. According to the source code in agent/server.py, this scaffolding includes:

  • check_message_queue_before_model – Injects new user messages (like follow-up Slack or Linear comments) before each model call
  • open_pr_if_needed – Guarantees a PR is opened even if the LLM forgets to call the tool
  • ToolErrorMiddleware – Catches tool failures and surfaces them as agent messages for recovery

This deterministic orchestration mirrors the patterns used by internal teams at major tech companies, ensuring the agent handles edge cases gracefully without human intervention.

Multi-Channel Invocation Surfaces

The same agent instance can be triggered from Slack, Linear, or GitHub webhooks via agent/webapp.py. Each invocation surface creates a deterministic LangGraph thread ID, ensuring follow-up messages route to the correct running agent instance. This multi-channel support allows teams to interact with coding agents through their existing communication workflows while maintaining conversation context across asynchronous platforms.

Practical Code Examples

The following examples demonstrate how to customize and interact with Open SWE agents using the actual implementation patterns from the repository.

Configuring a Custom Agent

To spin up a customized agent with model selection based on the trigger source:

from agent.server import get_agent  # the entry point

# Example: use a faster model for Slack Q&A, full model for Linear tickets

async def custom_agent(config):
    source = config["configurable"].get("source")
    if source == "slack":
        model = make_model("anthropic:claude-sonnet-4-6", temperature=0, max_tokens=16_000)
    else:
        model = make_model("anthropic:claude-opus-4-6", temperature=0, max_tokens=20_000)

    return create_deep_agent(
        model=model,
        system_prompt=construct_system_prompt(repo_dir, ...),
        tools=[http_request, fetch_url, commit_and_open_pr, linear_comment, slack_thread_reply],
        backend=sandbox_backend,
        middleware=[
            ToolErrorMiddleware(),
            check_message_queue_before_model,
            ensure_no_empty_msg,
            open_pr_if_needed,
        ],
    )

Source: agent/server.py – create_deep_agent call and model selection logic.

Creating Pull Requests Programmatically

When the agent determines changes are complete, it calls the commit_and_open_pr tool:


# Inside an agent step (the LLM calls this tool)

result = commit_and_open_pr(
    title="fix: resolve auth bug [closes AA-123]",
    body="""

## Description

Fixes a null‑pointer exception in the auth flow.

Resolves AA-123

## Test Plan

- [ ] Verify login works for users without a profile
""",
    commit_message=None,
)
print(result["pr_url"])   # URL of the drafted PR

Implementation details in agent/tools/commit_and_open_pr.py (line 27).

Selecting Sandbox Providers

Configure the execution environment via environment variables before starting the FastAPI server:


# Use a Daytona sandbox (cloud container) instead of the default LangSmith sandbox

export SANDBOX_TYPE=daytona
python -m agent.server  # starts the FastAPI webhook server with the new backend

Factory mapping is defined in agent/utils/sandbox.py (line 9).

Summary

  • Open SWE provides a composable agent harness via create_deep_agent in agent/server.py that integrates with the Deep Agents framework
  • Isolated execution is guaranteed through configurable sandboxes (LangSmith, Daytona, Modal, Runloop, or local) managed in agent/utils/sandbox.py
  • A curated toolset in agent/tools/__init__.py provides focused capabilities for shell execution, HTTP requests, and GitHub PR creation
  • Deterministic middleware ensures reliability through automated PR creation and message queue handling
  • Multi-channel support via agent/webapp.py enables triggering from Slack, Linear, and GitHub with persistent thread management

Frequently Asked Questions

How does Open SWE differ from other AI coding assistants?

Unlike black-box coding tools, Open SWE is a fully transparent framework that you fork and customize. It uses the Deep Agents framework to compose agents deterministically rather than prompting a generic LLM, and it enforces safety through mandatory sandboxed execution via the SandboxBackendProtocol implemented in agent/utils/sandbox.py.

Which sandbox providers does Open SWE support?

Open SWE supports five sandbox backends configurable via the SANDBOX_TYPE environment variable: langsmith, daytona, modal, runloop, and local. The factory function create_sandbox in agent/utils/sandbox.py instantiates the appropriate backend, allowing teams to choose between cloud containers or local development environments.

Can I customize the tools available to my Open SWE agent?

Yes, while Open SWE provides a curated default set in agent/tools/__init__.py including commit_and_open_pr and linear_comment, you can extend or modify the toolset by adding custom tools to the tools array passed to create_deep_agent in agent/server.py. This ensures the agent only has access to operations relevant to your specific workflow.

How does Open SWE handle ongoing conversations across different platforms?

Open SWE uses deterministic LangGraph thread IDs created in agent/webapp.py to route follow-up messages from Slack, Linear, or GitHub to the correct active agent instance. The check_message_queue_before_model middleware injects these follow-ups before each model call, enabling natural multi-turn conversations across asynchronous communication channels.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →