Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
aa4ed81
fix(copilot): inject actual working directory into SDK system prompt
majdyz Feb 26, 2026
a092c24
Merge branch 'master' of github.com:Significant-Gravitas/AutoGPT into…
majdyz Feb 26, 2026
224a8ca
fix(copilot): guard cwd precompute and remove unrelated frontend changes
majdyz Feb 26, 2026
a5d6e7d
fix(copilot): move makedirs into early cwd try/except
majdyz Feb 26, 2026
15bdb09
fix(copilot): replace _precomputed_cwd with sdk_cwd directly
majdyz Feb 26, 2026
cfb0afb
feat(copilot): add E2B cloud sandbox integration for persistent bash …
majdyz Feb 26, 2026
5167948
fix(copilot): guard e2b integration test against pytest collection crash
majdyz Feb 26, 2026
7d98f1b
fix(copilot): address CodeRabbit review comments
majdyz Feb 26, 2026
cb35d46
fix(copilot/e2b): path traversal guard + race-free sandbox creation
majdyz Feb 26, 2026
bb59655
merge: resolve conflict with master (cwd inside try/finally)
majdyz Feb 27, 2026
408155e
feat(copilot): route file tools through E2B sandbox when active
majdyz Feb 27, 2026
600851b
fix(copilot): make workspace_files tests async to match _resolve_writ…
majdyz Feb 27, 2026
e1b2a31
fix(copilot): use integer timeouts for E2B sandbox commands
majdyz Feb 27, 2026
70da86b
fix(copilot): harden E2B file tools and sandbox path handling
majdyz Feb 27, 2026
03fdc28
fix(copilot): validate sandbox path boundaries and cast timeout to int
majdyz Feb 27, 2026
d3d5b88
fix(copilot): remove dead sync code, fix config description, align lo…
majdyz Feb 28, 2026
5fb5f4e
Merge remote-tracking branch 'origin/dev' into feat/improve-copilot-file
majdyz Feb 28, 2026
ae8e669
fix(copilot): simplify E2B file tools, harden DB sanitization, add ou…
majdyz Feb 28, 2026
47c21b2
fix(copilot): disable SDK built-in Read in E2B mode
majdyz Feb 28, 2026
b5957ca
fix(copilot): harden file access — session-scoped tool-results, share…
majdyz Feb 28, 2026
08973c5
fix(copilot): prevent duplicate sandbox creation on lock contention
majdyz Feb 28, 2026
e594aff
fix(copilot): clean up e2b_file_tools imports, remove manual test
majdyz Feb 28, 2026
08287f0
fix(copilot): set _current_project_dir in security_hooks_test
majdyz Feb 28, 2026
008146b
fix(copilot): add defense-in-depth to _read_local and path validation…
majdyz Feb 28, 2026
3ff7327
fix(copilot): cap MCP tool response size to prevent SDK buffer overflow
majdyz Feb 28, 2026
76b1232
fix(copilot): centralize MCP tool truncation and stash, improve front…
majdyz Feb 28, 2026
0e2e0b5
fix(copilot): cleanup — E2B default on, revert unrelated frontend cha…
majdyz Feb 28, 2026
a14e88b
fix(copilot): simplify e2b_sandbox.py, move imports to top-level
majdyz Feb 28, 2026
3959aff
fix(copilot): clean up e2b_file_tools — merge MCP helpers, reduce boi…
majdyz Feb 28, 2026
a3dc0e1
fix(copilot): deduplicate E2B_WORKDIR, move imports to top-level, add…
majdyz Feb 28, 2026
69073d1
fix(copilot): add error handling for sandbox write in _save_to_path
majdyz Feb 28, 2026
060661b
fix(copilot): add error handling for local write in _save_to_path
majdyz Mar 1, 2026
7ee1e8b
fix(copilot): read sandbox files as bytes with utf-8 decode fallback
majdyz Mar 1, 2026
85dfaf1
fix(copilot): try reconnecting before raising on lock contention
majdyz Mar 1, 2026
97097fe
Merge remote-tracking branch 'origin/dev' into feat/improve-copilot-file
majdyz Mar 1, 2026
a878261
fix(copilot): address reviewer should-fix items
majdyz Mar 1, 2026
0b3faa7
feat(copilot): add kill_sandbox() for explicit E2B cleanup on session…
majdyz Mar 1, 2026
bc57672
fix(copilot): address reviewer v7 should-fix items
majdyz Mar 1, 2026
41da564
test(copilot): add kill_sandbox timeout test
majdyz Mar 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions autogpt_platform/backend/backend/copilot/sdk/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,30 @@ def available(self) -> bool:
# IMPORTANT: Must be less than frontend timeout (12s in useCopilotPage.ts)
_HEARTBEAT_INTERVAL = 10.0 # seconds


# Appended to the system prompt to inform the agent about available tools.
# The SDK built-in Bash is NOT available — use mcp__copilot__bash_exec instead,
# which has kernel-level network isolation (unshare --net).
_SDK_TOOL_SUPPLEMENT = """
def _build_sdk_tool_supplement(cwd: str) -> str:
"""Build the SDK tool supplement with the actual working directory injected."""
return f"""

## Tool notes

### Shell commands
- The SDK built-in Bash tool is NOT available. Use the `bash_exec` MCP tool
for shell commands — it runs in a network-isolated sandbox.

### Working directory
- Your working directory is: `{cwd}`
- All SDK Read/Write/Edit/Glob/Grep tools AND `bash_exec` operate inside this
directory. This is the ONLY writable path — do not attempt to read or write
anywhere else on the filesystem.
- Use relative paths or absolute paths under `{cwd}` for all file operations.

### Two storage systems — CRITICAL to understand

1. **Ephemeral working directory** (`/tmp/copilot-<session>/`):
1. **Ephemeral working directory** (`{cwd}`):
- Shared by SDK Read/Write/Edit/Glob/Grep tools AND `bash_exec`
- Files here are **lost between turns** — do NOT rely on them persisting
- Use for temporary work: running scripts, processing data, etc.
Expand Down Expand Up @@ -128,6 +138,7 @@ def available(self) -> bool:
All tasks must run in the foreground.
"""


STREAM_LOCK_PREFIX = "copilot:stream:lock:"


Expand Down Expand Up @@ -442,12 +453,16 @@ async def stream_chat_completion_sdk(
_background_tasks.add(task)
task.add_done_callback(_background_tasks.discard)

# Build system prompt (reuses non-SDK path with Langfuse support)
# Build system prompt (reuses non-SDK path with Langfuse support).
# Pre-compute the cwd here (deterministic, no side effects) so the exact
# working directory path can be injected into the supplement instead of
# the generic `/tmp/copilot-<session>/` placeholder.
has_history = len(session.messages) > 1
_precomputed_cwd = _make_sdk_cwd(session_id)
system_prompt, _ = await _build_system_prompt(
user_id, has_conversation_history=has_history
)
system_prompt += _SDK_TOOL_SUPPLEMENT
system_prompt += _build_sdk_tool_supplement(_precomputed_cwd)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
message_id = str(uuid.uuid4())
stream_id = str(uuid.uuid4())

Expand Down
Loading