agentcyberrange 0.1.0__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/PKG-INFO +27 -27
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/README.md +25 -22
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/examples/codex_cli.py +6 -5
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/pyproject.toml +0 -5
- agentcyberrange-0.1.2/src/agentcyberrange/_version.py +1 -0
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/src/agentcyberrange/runner.py +4 -4
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/src/agentcyberrange/scheduler.py +19 -2
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/src/agentcyberrange/submission.py +5 -5
- agentcyberrange-0.1.0/src/agentcyberrange/_version.py +0 -1
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/.gitignore +0 -0
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/LICENSE +0 -0
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/examples/manual_client.py +0 -0
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/examples/quickstart.py +0 -0
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/src/agentcyberrange/__init__.py +0 -0
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/src/agentcyberrange/client.py +0 -0
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/src/agentcyberrange/errors.py +0 -0
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/src/agentcyberrange/handles.py +0 -0
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/src/agentcyberrange/models.py +0 -0
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/src/agentcyberrange/py.typed +0 -0
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/src/agentcyberrange/state.py +0 -0
- {agentcyberrange-0.1.0 → agentcyberrange-0.1.2}/uv.lock +0 -0
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: agentcyberrange
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Async Python SDK for Agent Cyber Range
|
|
5
|
-
Project-URL: Homepage, https://github.com/cynicalight/py-agentcyberrange
|
|
6
|
-
Project-URL: Repository, https://github.com/cynicalight/py-agentcyberrange
|
|
7
|
-
Project-URL: Issues, https://github.com/cynicalight/py-agentcyberrange/issues
|
|
8
5
|
Author: Agent Cyber Range contributors
|
|
9
6
|
License-Expression: MIT
|
|
10
7
|
License-File: LICENSE
|
|
@@ -35,9 +32,7 @@ Agent Cyber Range evaluation platform. It discovers the available Challenges,
|
|
|
35
32
|
keeps a bounded number of Arenas running, waits for capacity, and submits each
|
|
36
33
|
Arena when the Agent finishes or reaches its deadline.
|
|
37
34
|
|
|
38
|
-
|
|
39
|
-
locally from this [GitHub repository](https://github.com/cynicalight/py-agentcyberrange)
|
|
40
|
-
before requesting an official evaluation.
|
|
35
|
+
Access to the evaluation service requires a Task Token issued by Agent Cyber Range.
|
|
41
36
|
|
|
42
37
|
Python 3.11 or newer is required.
|
|
43
38
|
|
|
@@ -110,7 +105,7 @@ The Quick Start keeps the main customization points visible: the Agent callback,
|
|
|
110
105
|
server-provided Prompt, and two concurrent Agents. The SDK returns the available
|
|
111
106
|
Challenge list, and the example selects the first five for this run. It leaves
|
|
112
107
|
`agent_timeout` unset, so Web Challenges use the 30-minute default and post Challenges use
|
|
113
|
-
the 2-hour default. Pass `agent_timeout` directly to apply one
|
|
108
|
+
the 2-hour default. Pass `agent_timeout` directly to apply one exact limit across the
|
|
114
109
|
selected Challenges.
|
|
115
110
|
|
|
116
111
|
Environment variables are reserved for connection configuration
|
|
@@ -118,22 +113,22 @@ Environment variables are reserved for connection configuration
|
|
|
118
113
|
policy such as concurrency, Agent timeout, model, and permission mode stays explicit in
|
|
119
114
|
Python arguments or CLI flags instead of hidden process-global configuration.
|
|
120
115
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
`agent_timeout` is an optional local limit in seconds. `run_agent()` applies
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if
|
|
134
|
-
archive instead.
|
|
135
|
-
|
|
136
|
-
|
|
116
|
+
When `agent_timeout` is omitted, the SDK uses a 30-minute Web (non-post) timeout or a
|
|
117
|
+
2-hour post timeout. Fleet gives both Challenge types a 24-hour Arena lease as the final
|
|
118
|
+
resource deadline.
|
|
119
|
+
|
|
120
|
+
`agent_timeout` is an optional local limit in seconds. `run_agent()` applies an explicit
|
|
121
|
+
value without the old Web/Post type-specific cap. For example, `agent_timeout=3600` runs
|
|
122
|
+
both Web and post Agents for up to 60 minutes. The effective deadline is the earlier of
|
|
123
|
+
this local limit and the Arena's 24-hour server lease. When the local timeout is reached,
|
|
124
|
+
the SDK signals `arena.cancel_event` and cancels the Agent callback. It then allows
|
|
125
|
+
cancellation cleanup and Web output finalization for up to two minutes before submitting;
|
|
126
|
+
submission happens sooner when cleanup finishes sooner. A post Challenge is submitted
|
|
127
|
+
with an empty body. A non-post callback may return its output archive during cancellation;
|
|
128
|
+
if no archive is available by the finalization deadline, the SDK submits a minimal empty
|
|
129
|
+
`final_answer` archive instead. The backend closes the Arena after this terminal
|
|
130
|
+
submission. The returned task outcome records the timeout in `error_code` and
|
|
131
|
+
`error_message`.
|
|
137
132
|
|
|
138
133
|
`on_event` receives lifecycle and retry events. Capacity waits include the HTTP status,
|
|
139
134
|
error code, request ID, `Retry-After`, and attempt number in `SchedulerEvent`, so callers
|
|
@@ -172,8 +167,13 @@ The Codex example passes the server-provided `arena.task_prompt` to Codex unchan
|
|
|
172
167
|
removes `AGENTCYBERRANGE_TASK_TOKEN` and `AGENTCYBERRANGE_BASE_URL` from the child
|
|
173
168
|
environment, so Codex cannot directly operate the control plane. If Codex creates a
|
|
174
169
|
`final_answer/` directory for a non-post Challenge, the callback archives it under
|
|
175
|
-
`.agentcyberrange/agent-output/` and returns that archive path to the Scheduler.
|
|
176
|
-
|
|
170
|
+
`.agentcyberrange/agent-output/` and returns that archive path to the Scheduler.
|
|
171
|
+
|
|
172
|
+
When an SDK timeout or Arena deadline cancels the callback, the example first stops Codex
|
|
173
|
+
and then archives any existing `final_answer/` before the temporary workspace is removed.
|
|
174
|
+
The Scheduler submits that archive immediately. If the directory does not exist, the
|
|
175
|
+
Scheduler submits a minimal empty `final_answer` archive instead. A post Challenge returns
|
|
176
|
+
`None` and is submitted with an empty body.
|
|
177
177
|
|
|
178
178
|
## Low-level client
|
|
179
179
|
|
|
@@ -5,9 +5,7 @@ Agent Cyber Range evaluation platform. It discovers the available Challenges,
|
|
|
5
5
|
keeps a bounded number of Arenas running, waits for capacity, and submits each
|
|
6
6
|
Arena when the Agent finishes or reaches its deadline.
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
locally from this [GitHub repository](https://github.com/cynicalight/py-agentcyberrange)
|
|
10
|
-
before requesting an official evaluation.
|
|
8
|
+
Access to the evaluation service requires a Task Token issued by Agent Cyber Range.
|
|
11
9
|
|
|
12
10
|
Python 3.11 or newer is required.
|
|
13
11
|
|
|
@@ -80,7 +78,7 @@ The Quick Start keeps the main customization points visible: the Agent callback,
|
|
|
80
78
|
server-provided Prompt, and two concurrent Agents. The SDK returns the available
|
|
81
79
|
Challenge list, and the example selects the first five for this run. It leaves
|
|
82
80
|
`agent_timeout` unset, so Web Challenges use the 30-minute default and post Challenges use
|
|
83
|
-
the 2-hour default. Pass `agent_timeout` directly to apply one
|
|
81
|
+
the 2-hour default. Pass `agent_timeout` directly to apply one exact limit across the
|
|
84
82
|
selected Challenges.
|
|
85
83
|
|
|
86
84
|
Environment variables are reserved for connection configuration
|
|
@@ -88,22 +86,22 @@ Environment variables are reserved for connection configuration
|
|
|
88
86
|
policy such as concurrency, Agent timeout, model, and permission mode stays explicit in
|
|
89
87
|
Python arguments or CLI flags instead of hidden process-global configuration.
|
|
90
88
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
`agent_timeout` is an optional local limit in seconds. `run_agent()` applies
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if
|
|
104
|
-
archive instead.
|
|
105
|
-
|
|
106
|
-
|
|
89
|
+
When `agent_timeout` is omitted, the SDK uses a 30-minute Web (non-post) timeout or a
|
|
90
|
+
2-hour post timeout. Fleet gives both Challenge types a 24-hour Arena lease as the final
|
|
91
|
+
resource deadline.
|
|
92
|
+
|
|
93
|
+
`agent_timeout` is an optional local limit in seconds. `run_agent()` applies an explicit
|
|
94
|
+
value without the old Web/Post type-specific cap. For example, `agent_timeout=3600` runs
|
|
95
|
+
both Web and post Agents for up to 60 minutes. The effective deadline is the earlier of
|
|
96
|
+
this local limit and the Arena's 24-hour server lease. When the local timeout is reached,
|
|
97
|
+
the SDK signals `arena.cancel_event` and cancels the Agent callback. It then allows
|
|
98
|
+
cancellation cleanup and Web output finalization for up to two minutes before submitting;
|
|
99
|
+
submission happens sooner when cleanup finishes sooner. A post Challenge is submitted
|
|
100
|
+
with an empty body. A non-post callback may return its output archive during cancellation;
|
|
101
|
+
if no archive is available by the finalization deadline, the SDK submits a minimal empty
|
|
102
|
+
`final_answer` archive instead. The backend closes the Arena after this terminal
|
|
103
|
+
submission. The returned task outcome records the timeout in `error_code` and
|
|
104
|
+
`error_message`.
|
|
107
105
|
|
|
108
106
|
`on_event` receives lifecycle and retry events. Capacity waits include the HTTP status,
|
|
109
107
|
error code, request ID, `Retry-After`, and attempt number in `SchedulerEvent`, so callers
|
|
@@ -142,8 +140,13 @@ The Codex example passes the server-provided `arena.task_prompt` to Codex unchan
|
|
|
142
140
|
removes `AGENTCYBERRANGE_TASK_TOKEN` and `AGENTCYBERRANGE_BASE_URL` from the child
|
|
143
141
|
environment, so Codex cannot directly operate the control plane. If Codex creates a
|
|
144
142
|
`final_answer/` directory for a non-post Challenge, the callback archives it under
|
|
145
|
-
`.agentcyberrange/agent-output/` and returns that archive path to the Scheduler.
|
|
146
|
-
|
|
143
|
+
`.agentcyberrange/agent-output/` and returns that archive path to the Scheduler.
|
|
144
|
+
|
|
145
|
+
When an SDK timeout or Arena deadline cancels the callback, the example first stops Codex
|
|
146
|
+
and then archives any existing `final_answer/` before the temporary workspace is removed.
|
|
147
|
+
The Scheduler submits that archive immediately. If the directory does not exist, the
|
|
148
|
+
Scheduler submits a minimal empty `final_answer` archive instead. A post Challenge returns
|
|
149
|
+
`None` and is submitted with an empty body.
|
|
147
150
|
|
|
148
151
|
## Low-level client
|
|
149
152
|
|
|
@@ -63,13 +63,14 @@ async def call_codex(arena: ArenaHandle) -> AgentOutputPath | None:
|
|
|
63
63
|
await process.communicate(arena.task_prompt.encode())
|
|
64
64
|
except asyncio.CancelledError:
|
|
65
65
|
await stop_codex(process)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
if not arena.cancel_event.is_set():
|
|
67
|
+
raise
|
|
68
|
+
else:
|
|
69
|
+
if process.returncode != 0:
|
|
70
|
+
raise RuntimeError(f"Codex exited with status {process.returncode}")
|
|
69
71
|
if is_post_challenge(arena.challenge_id):
|
|
70
72
|
return None
|
|
71
|
-
|
|
72
|
-
return agent_output
|
|
73
|
+
return archive_agent_output(workspace, arena.arena_id)
|
|
73
74
|
|
|
74
75
|
|
|
75
76
|
async def main() -> None:
|
|
@@ -27,11 +27,6 @@ dependencies = [
|
|
|
27
27
|
"pydantic>=2.7",
|
|
28
28
|
]
|
|
29
29
|
|
|
30
|
-
[project.urls]
|
|
31
|
-
Homepage = "https://github.com/cynicalight/py-agentcyberrange"
|
|
32
|
-
Repository = "https://github.com/cynicalight/py-agentcyberrange"
|
|
33
|
-
Issues = "https://github.com/cynicalight/py-agentcyberrange/issues"
|
|
34
|
-
|
|
35
30
|
[project.optional-dependencies]
|
|
36
31
|
dev = [
|
|
37
32
|
"build>=1.2",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.2"
|
|
@@ -34,10 +34,10 @@ async def run_agent(
|
|
|
34
34
|
non-post Challenge; when it returns ``None``, the Scheduler submits a minimal empty
|
|
35
35
|
``final_answer`` archive instead. Post Challenges are always submitted with an empty
|
|
36
36
|
body. ``max_concurrency`` defaults to one. Agent callbacks default to a
|
|
37
|
-
30-minute Web timeout or a 2-hour post timeout
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
selects an ordered subset. Connection settings default to
|
|
37
|
+
30-minute Web timeout or a 2-hour post timeout. ``agent_timeout`` optionally sets one
|
|
38
|
+
uniform limit for every selected Challenge without applying the old type-specific
|
|
39
|
+
cap. The Arena's 24-hour server lease remains the final resource deadline.
|
|
40
|
+
``challenge_ids`` optionally selects an ordered subset. Connection settings default to
|
|
41
41
|
``AGENTCYBERRANGE_BASE_URL`` and ``AGENTCYBERRANGE_TASK_TOKEN``. Passing a client is
|
|
42
42
|
primarily useful for embedding and testing; a caller-owned client is not closed by
|
|
43
43
|
this function. ``on_event`` reports capacity waits and lifecycle failures without
|
|
@@ -40,6 +40,7 @@ from .submission import is_post_challenge, resolve_agent_timeout
|
|
|
40
40
|
ArenaReadyHandler = Callable[[ArenaHandle], Awaitable[AgentOutputPath | None]]
|
|
41
41
|
EventHandler = Callable[[SchedulerEvent], Awaitable[None] | None]
|
|
42
42
|
AGENT_OUTPUT_FINALIZATION_TIMEOUT_SECONDS = 30.0
|
|
43
|
+
CUSTOM_TIMEOUT_FINALIZATION_SECONDS = 2 * 60.0
|
|
43
44
|
|
|
44
45
|
|
|
45
46
|
def _error_details(error: AgentCyberRangeError) -> dict[str, JsonValue]:
|
|
@@ -551,12 +552,22 @@ class RoundScheduler:
|
|
|
551
552
|
error_code = "agent_timeout_reached"
|
|
552
553
|
error_message = "Agent did not return before its configured timeout"
|
|
553
554
|
if is_post_challenge(handle.challenge_id):
|
|
555
|
+
if task.agent_timeout is not None:
|
|
556
|
+
await self._cancelled_agent_output(
|
|
557
|
+
callback_task,
|
|
558
|
+
timeout_seconds=CUSTOM_TIMEOUT_FINALIZATION_SECONDS,
|
|
559
|
+
)
|
|
554
560
|
submission = await handle.submit()
|
|
555
561
|
else:
|
|
556
562
|
submission = await self._submit_cancelled_non_post(
|
|
557
563
|
handle,
|
|
558
564
|
callback_task,
|
|
559
565
|
deadline=False,
|
|
566
|
+
timeout_seconds=(
|
|
567
|
+
CUSTOM_TIMEOUT_FINALIZATION_SECONDS
|
|
568
|
+
if task.agent_timeout is not None
|
|
569
|
+
else AGENT_OUTPUT_FINALIZATION_TIMEOUT_SECONDS
|
|
570
|
+
),
|
|
560
571
|
)
|
|
561
572
|
else:
|
|
562
573
|
agent_output: AgentOutputPath | None = None
|
|
@@ -596,11 +607,13 @@ class RoundScheduler:
|
|
|
596
607
|
@staticmethod
|
|
597
608
|
async def _cancelled_agent_output(
|
|
598
609
|
callback_task: asyncio.Future[AgentOutputPath | None],
|
|
610
|
+
*,
|
|
611
|
+
timeout_seconds: float = AGENT_OUTPUT_FINALIZATION_TIMEOUT_SECONDS,
|
|
599
612
|
) -> AgentOutputPath | None:
|
|
600
613
|
try:
|
|
601
614
|
return await asyncio.wait_for(
|
|
602
615
|
callback_task,
|
|
603
|
-
timeout=
|
|
616
|
+
timeout=timeout_seconds,
|
|
604
617
|
)
|
|
605
618
|
except asyncio.CancelledError:
|
|
606
619
|
return None
|
|
@@ -613,8 +626,12 @@ class RoundScheduler:
|
|
|
613
626
|
callback_task: asyncio.Future[AgentOutputPath | None],
|
|
614
627
|
*,
|
|
615
628
|
deadline: bool,
|
|
629
|
+
timeout_seconds: float = AGENT_OUTPUT_FINALIZATION_TIMEOUT_SECONDS,
|
|
616
630
|
) -> SubmissionResult:
|
|
617
|
-
agent_output = await self._cancelled_agent_output(
|
|
631
|
+
agent_output = await self._cancelled_agent_output(
|
|
632
|
+
callback_task,
|
|
633
|
+
timeout_seconds=timeout_seconds,
|
|
634
|
+
)
|
|
618
635
|
return await self._submit_non_post(handle, agent_output, deadline=deadline)
|
|
619
636
|
|
|
620
637
|
@staticmethod
|
|
@@ -10,15 +10,15 @@ def is_post_challenge(challenge_id: str) -> bool:
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
def resolve_agent_timeout(challenge_id: str, requested_timeout: float | None) -> float:
|
|
13
|
-
"""Return
|
|
14
|
-
|
|
13
|
+
"""Return an explicit timeout unchanged, or the Challenge type default."""
|
|
14
|
+
if requested_timeout is not None:
|
|
15
|
+
return requested_timeout
|
|
16
|
+
default = (
|
|
15
17
|
POST_AGENT_TIMEOUT_SECONDS
|
|
16
18
|
if is_post_challenge(challenge_id)
|
|
17
19
|
else WEB_AGENT_TIMEOUT_SECONDS
|
|
18
20
|
)
|
|
19
|
-
|
|
20
|
-
return float(maximum)
|
|
21
|
-
return min(requested_timeout, maximum)
|
|
21
|
+
return float(default)
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
__all__ = [
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.1.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|