Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
12 changes: 12 additions & 0 deletions rock/actions/sandbox/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ class Command(BaseModel):
session_type: Literal["bash"] = "bash"
command: str | list[str]

timeout: float | None = 1200
"""The timeout for the command. None means no timeout."""

env: dict[str, str] | None = None
"""Environment variables to pass to the command."""

cwd: str | None = None
"""The current working directory to run the command in."""

sandbox_id: str | None = None
"""The sandbox id derived from init_env."""


class CreateBashSessionRequest(BaseModel):
session_type: Literal["bash"] = "bash"
Expand Down
5 changes: 4 additions & 1 deletion rock/sdk/sandbox/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ async def execute(self, command: Command) -> CommandResponse:
headers = self._build_headers()
data = {
"command": command.command,
"sandbox_id": self.sandbox_id,
"sandbox_id": self._sandbox_id,
"timeout": command.timeout,
"cwd": command.cwd,
"env": command.env
}
try:
response = await HttpUtils.post(url, headers, data)
Expand Down
17 changes: 16 additions & 1 deletion tests/integration/sdk/sandbox/test_sdk_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def test_sandbox_get_status(admin_remote_server):
await sandbox.start()
assert "Failed to start sandbox" in str(exc_info.value)
sandbox.stop()

@pytest.mark.need_admin
@SKIP_IF_NO_DOCKER
@pytest.mark.asyncio
Expand All @@ -72,3 +72,18 @@ async def test_update_mount(sandbox_instance: Sandbox):
with pytest.raises(Exception) as exc_info:
await sandbox_instance.arun(session="default", cmd="touch /tmp/local_files/test.txt")
assert "Read-only file system" in str(exc_info.value)


@pytest.mark.need_admin
@SKIP_IF_NO_DOCKER
@pytest.mark.asyncio
async def test_execute(sandbox_instance: Sandbox):
from rock.actions.sandbox.request import Command

curr_status = await sandbox_instance.get_status()
if curr_status.is_alive:
resp1 = await sandbox_instance.execute(Command(command="pwd", cwd="/root"))
assert resp1.stdout.strip() == "/root"
resp2 = await sandbox_instance.execute(Command(command="pwd", cwd="/tmp"))
assert resp2.stdout.strip() == "/tmp"

Loading